diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index 9c9d61f..46642d8 100644 --- a/.kokoro/docs/common.cfg +++ b/.kokoro/docs/common.cfg @@ -30,7 +30,7 @@ env_vars: { env_vars: { key: "V2_STAGING_BUCKET" - value: "docs-staging-v2-staging" + value: "docs-staging-v2" } # It will upload the docker image after successful builds. diff --git a/.kokoro/test-samples.sh b/.kokoro/test-samples.sh index 320cf11..1568e87 100755 --- a/.kokoro/test-samples.sh +++ b/.kokoro/test-samples.sh @@ -28,6 +28,12 @@ if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then git checkout $LATEST_RELEASE fi +# Exit early if samples directory doesn't exist +if [ ! -d "./samples" ]; then + echo "No tests run. `./samples` not found" + exit 0 +fi + # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -101,4 +107,4 @@ cd "$ROOT" # Workaround for Kokoro permissions issue: delete secrets rm testing/{test-env.sh,client-secrets.json,service-account.json} -exit "$RTN" \ No newline at end of file +exit "$RTN" diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b3d1f60..039f436 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,44 +1,95 @@ -# Contributor Code of Conduct +# Code of Conduct -As contributors and maintainers of this project, -and in the interest of fostering an open and welcoming community, -we pledge to respect all people who contribute through reporting issues, -posting feature requests, updating documentation, -submitting pull requests or patches, and other activities. +## Our Pledge -We are committed to making participation in this project -a harassment-free experience for everyone, -regardless of level of experience, gender, gender identity and expression, -sexual orientation, disability, personal appearance, -body size, race, ethnicity, age, religion, or nationality. +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery -* Personal attacks -* Trolling or insulting/derogatory comments -* Public or private harassment -* Publishing other's private information, -such as physical or electronic -addresses, without explicit permission -* Other unethical or unprofessional conduct. +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct. -By adopting this Code of Conduct, -project maintainers commit themselves to fairly and consistently -applying these principles to every aspect of managing this project. -Project maintainers who do not follow or enforce the Code of Conduct -may be permanently removed from the project team. - -This code of conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior -may be reported by opening an issue -or contacting one or more of the project maintainers. - -This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, -available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + + +Reports should be directed to *googleapis-stewards@google.com*, the +Project Steward(s) for *Google Cloud Client Libraries*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out to the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 20f6372..033c91a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -349,6 +349,7 @@ "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), "grpc": ("https://grpc.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), } diff --git a/docs/functions_v1/types.rst b/docs/functions_v1/types.rst index 4a83832..e2d24d0 100644 --- a/docs/functions_v1/types.rst +++ b/docs/functions_v1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Functions v1 API .. automodule:: google.cloud.functions_v1.types :members: + :show-inheritance: diff --git a/functions-v1-py.tar.gz b/functions-v1-py.tar.gz deleted file mode 100644 index e69de29..0000000 diff --git a/google/cloud/functions_v1/services/cloud_functions_service/async_client.py b/google/cloud/functions_v1/services/cloud_functions_service/async_client.py index db03b58..943640a 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/async_client.py +++ b/google/cloud/functions_v1/services/cloud_functions_service/async_client.py @@ -59,9 +59,49 @@ class CloudFunctionsServiceAsyncClient: CloudFunctionsServiceClient.parse_cloud_function_path ) + common_billing_account_path = staticmethod( + CloudFunctionsServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + CloudFunctionsServiceClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(CloudFunctionsServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + CloudFunctionsServiceClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + CloudFunctionsServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + CloudFunctionsServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(CloudFunctionsServiceClient.common_project_path) + parse_common_project_path = staticmethod( + CloudFunctionsServiceClient.parse_common_project_path + ) + + common_location_path = staticmethod( + CloudFunctionsServiceClient.common_location_path + ) + parse_common_location_path = staticmethod( + CloudFunctionsServiceClient.parse_common_location_path + ) + from_service_account_file = CloudFunctionsServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> CloudFunctionsServiceTransport: + """Return the transport used by the client instance. + + Returns: + CloudFunctionsServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(CloudFunctionsServiceClient).get_transport_class, type(CloudFunctionsServiceClient), @@ -215,7 +255,8 @@ async def get_function( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -300,7 +341,8 @@ async def create_function( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([location, function]): + has_flattened_params = any([location, function]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -386,7 +428,8 @@ async def update_function( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([function]): + has_flattened_params = any([function]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -485,7 +528,8 @@ async def delete_function( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -572,7 +616,8 @@ async def call_function( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, data]): + has_flattened_params = any([name, data]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." diff --git a/google/cloud/functions_v1/services/cloud_functions_service/client.py b/google/cloud/functions_v1/services/cloud_functions_service/client.py index 2a900d4..bdeb8b1 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/client.py +++ b/google/cloud/functions_v1/services/cloud_functions_service/client.py @@ -142,6 +142,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> CloudFunctionsServiceTransport: + """Return the transport used by the client instance. + + Returns: + CloudFunctionsServiceTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def cloud_function_path(project: str, location: str, function: str,) -> str: """Return a fully-qualified cloud_function string.""" @@ -158,6 +167,65 @@ def parse_cloud_function_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, @@ -193,10 +261,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: diff --git a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py b/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py index 94f9e36..9507fc2 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py +++ b/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py @@ -94,10 +94,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -106,6 +106,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -113,6 +115,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -149,6 +152,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -226,12 +230,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property diff --git a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py b/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py index 46a8835..b292db3 100644 --- a/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py +++ b/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py @@ -151,6 +151,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -158,6 +160,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -194,6 +197,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" diff --git a/google/cloud/functions_v1/types/functions.py b/google/cloud/functions_v1/types/functions.py index caff319..b448b46 100644 --- a/google/cloud/functions_v1/types/functions.py +++ b/google/cloud/functions_v1/types/functions.py @@ -392,7 +392,7 @@ class CreateFunctionRequest(proto.Message): location = proto.Field(proto.STRING, number=1) - function = proto.Field(proto.MESSAGE, number=2, message=CloudFunction,) + function = proto.Field(proto.MESSAGE, number=2, message="CloudFunction",) class UpdateFunctionRequest(proto.Message): @@ -406,7 +406,7 @@ class UpdateFunctionRequest(proto.Message): request. """ - function = proto.Field(proto.MESSAGE, number=1, message=CloudFunction,) + function = proto.Field(proto.MESSAGE, number=1, message="CloudFunction",) update_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) @@ -473,7 +473,7 @@ class ListFunctionsResponse(proto.Message): def raw_page(self): return self - functions = proto.RepeatedField(proto.MESSAGE, number=1, message=CloudFunction,) + functions = proto.RepeatedField(proto.MESSAGE, number=1, message="CloudFunction",) next_page_token = proto.Field(proto.STRING, number=2) diff --git a/noxfile.py b/noxfile.py index 8aa27d6..f975381 100644 --- a/noxfile.py +++ b/noxfile.py @@ -28,7 +28,7 @@ DEFAULT_PYTHON_VERSION = "3.8" SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -72,7 +72,9 @@ def default(session): # Install all test dependencies, then install this package in-place. session.install("asyncmock", "pytest-asyncio") - session.install("mock", "pytest", "pytest-cov") + session.install( + "mock", "pytest", "pytest-cov", + ) session.install("-e", ".") # Run py.test against the unit tests. diff --git a/scripts/fixup_functions_v1_keywords.py b/scripts/fixup_functions_v1_keywords.py index b77cd5b..78b0502 100644 --- a/scripts/fixup_functions_v1_keywords.py +++ b/scripts/fixup_functions_v1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/setup.py b/setup.py index ff89512..ff6532c 100644 --- a/setup.py +++ b/setup.py @@ -41,8 +41,7 @@ platforms="Posix; MacOS X; Windows", include_package_data=True, install_requires=( - "google-api-core[grpc] >= 1.21.0, < 2.0.0dev", - "libcst >= 0.2.5", + "google-api-core[grpc] >= 1.22.0, < 2.0.0dev", "proto-plus >= 1.10.0", "grpc-google-iam-v1", ), diff --git a/synth.metadata b/synth.metadata index b26614c..8a83a6b 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,30 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-functions.git", - "sha": "94917c52dd83d18b8a3fd61e7f5d5c870c5a874c" + "remote": "git@github.com:googleapis/python-functions", + "sha": "8588ecb9705d7c345067e09b51798168012341f1" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "4f2a18a10e89afa485f4023bf31f2bb120a2d54d", - "internalRef": "335029068" + "sha": "e3e7e7ddb0fecd7bc61ca03b5a9ddb29cc9b48d8", + "internalRef": "342967619" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0762e8ee2ec21cdfc4d82020b985a104feb0453b" + "sha": "7fcc405a579d5d53a726ff3da1b7c8c08f0f2d58" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0762e8ee2ec21cdfc4d82020b985a104feb0453b" + "sha": "7fcc405a579d5d53a726ff3da1b7c8c08f0f2d58" } } ], @@ -40,93 +40,5 @@ "generator": "bazel" } } - ], - "generatedFiles": [ - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/populate-secrets.sh", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/functions_v1/services.rst", - "docs/functions_v1/types.rst", - "docs/multiprocessing.rst", - "functions-v1-py.tar.gz", - "google/cloud/functions/__init__.py", - "google/cloud/functions/py.typed", - "google/cloud/functions_v1/__init__.py", - "google/cloud/functions_v1/py.typed", - "google/cloud/functions_v1/services/__init__.py", - "google/cloud/functions_v1/services/cloud_functions_service/__init__.py", - "google/cloud/functions_v1/services/cloud_functions_service/async_client.py", - "google/cloud/functions_v1/services/cloud_functions_service/client.py", - "google/cloud/functions_v1/services/cloud_functions_service/pagers.py", - "google/cloud/functions_v1/services/cloud_functions_service/transports/__init__.py", - "google/cloud/functions_v1/services/cloud_functions_service/transports/base.py", - "google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py", - "google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py", - "google/cloud/functions_v1/types/__init__.py", - "google/cloud/functions_v1/types/functions.py", - "google/cloud/functions_v1/types/operations.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "scripts/decrypt-secrets.sh", - "scripts/fixup_functions_v1_keywords.py", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/unit/gapic/functions_v1/__init__.py", - "tests/unit/gapic/functions_v1/test_cloud_functions_service.py" ] } \ No newline at end of file diff --git a/tests/unit/gapic/functions_v1/test_cloud_functions_service.py b/tests/unit/gapic/functions_v1/test_cloud_functions_service.py index 54d1f20..0c2b31d 100644 --- a/tests/unit/gapic/functions_v1/test_cloud_functions_service.py +++ b/tests/unit/gapic/functions_v1/test_cloud_functions_service.py @@ -44,7 +44,6 @@ from google.cloud.functions_v1.services.cloud_functions_service import pagers from google.cloud.functions_v1.services.cloud_functions_service import transports from google.cloud.functions_v1.types import functions -from google.cloud.functions_v1.types import functions as gcf_functions from google.cloud.functions_v1.types import operations from google.iam.v1 import iam_policy_pb2 as iam_policy # type: ignore from google.iam.v1 import options_pb2 as options # type: ignore @@ -112,12 +111,12 @@ def test_cloud_functions_service_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "cloudfunctions.googleapis.com:443" + assert client.transport._host == "cloudfunctions.googleapis.com:443" def test_cloud_functions_service_client_get_transport_class(): @@ -489,7 +488,7 @@ def test_list_functions( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_functions), "__call__") as call: + with mock.patch.object(type(client.transport.list_functions), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.ListFunctionsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], @@ -504,6 +503,7 @@ def test_list_functions( assert args[0] == functions.ListFunctionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFunctionsPager) assert response.next_page_token == "next_page_token_value" @@ -516,19 +516,19 @@ def test_list_functions_from_dict(): @pytest.mark.asyncio -async def test_list_functions_async(transport: str = "grpc_asyncio"): +async def test_list_functions_async( + transport: str = "grpc_asyncio", request_type=functions.ListFunctionsRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.ListFunctionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_functions), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_functions), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.ListFunctionsResponse( @@ -543,7 +543,7 @@ async def test_list_functions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.ListFunctionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFunctionsAsyncPager) @@ -553,6 +553,11 @@ async def test_list_functions_async(transport: str = "grpc_asyncio"): assert response.unreachable == ["unreachable_value"] +@pytest.mark.asyncio +async def test_list_functions_async_from_dict(): + await test_list_functions_async(request_type=dict) + + def test_list_functions_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -564,7 +569,7 @@ def test_list_functions_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_functions), "__call__") as call: + with mock.patch.object(type(client.transport.list_functions), "__call__") as call: call.return_value = functions.ListFunctionsResponse() client.list_functions(request) @@ -591,9 +596,7 @@ async def test_list_functions_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_functions), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_functions), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.ListFunctionsResponse() ) @@ -614,7 +617,7 @@ def test_list_functions_pager(): client = CloudFunctionsServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_functions), "__call__") as call: + with mock.patch.object(type(client.transport.list_functions), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( functions.ListFunctionsResponse( @@ -652,7 +655,7 @@ def test_list_functions_pages(): client = CloudFunctionsServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_functions), "__call__") as call: + with mock.patch.object(type(client.transport.list_functions), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( functions.ListFunctionsResponse( @@ -685,9 +688,7 @@ async def test_list_functions_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_functions), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_functions), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -726,9 +727,7 @@ async def test_list_functions_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_functions), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_functions), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -768,7 +767,7 @@ def test_get_function( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_function), "__call__") as call: + with mock.patch.object(type(client.transport.get_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CloudFunction( name="name_value", @@ -798,6 +797,7 @@ def test_get_function( assert args[0] == functions.GetFunctionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, functions.CloudFunction) assert response.name == "name_value" @@ -839,19 +839,19 @@ def test_get_function_from_dict(): @pytest.mark.asyncio -async def test_get_function_async(transport: str = "grpc_asyncio"): +async def test_get_function_async( + transport: str = "grpc_asyncio", request_type=functions.GetFunctionRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.GetFunctionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.CloudFunction( @@ -878,7 +878,7 @@ async def test_get_function_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.GetFunctionRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.CloudFunction) @@ -917,6 +917,11 @@ async def test_get_function_async(transport: str = "grpc_asyncio"): assert response.build_id == "build_id_value" +@pytest.mark.asyncio +async def test_get_function_async_from_dict(): + await test_get_function_async(request_type=dict) + + def test_get_function_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -928,7 +933,7 @@ def test_get_function_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_function), "__call__") as call: + with mock.patch.object(type(client.transport.get_function), "__call__") as call: call.return_value = functions.CloudFunction() client.get_function(request) @@ -955,9 +960,7 @@ async def test_get_function_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_function), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.CloudFunction() ) @@ -980,7 +983,7 @@ def test_get_function_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_function), "__call__") as call: + with mock.patch.object(type(client.transport.get_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CloudFunction() @@ -1016,9 +1019,7 @@ async def test_get_function_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CloudFunction() @@ -1063,7 +1064,7 @@ def test_create_function( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_function), "__call__") as call: + with mock.patch.object(type(client.transport.create_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1084,19 +1085,19 @@ def test_create_function_from_dict(): @pytest.mark.asyncio -async def test_create_function_async(transport: str = "grpc_asyncio"): +async def test_create_function_async( + transport: str = "grpc_asyncio", request_type=functions.CreateFunctionRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.CreateFunctionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1108,12 +1109,17 @@ async def test_create_function_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.CreateFunctionRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_create_function_async_from_dict(): + await test_create_function_async(request_type=dict) + + def test_create_function_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1125,7 +1131,7 @@ def test_create_function_field_headers(): request.location = "location/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_function), "__call__") as call: + with mock.patch.object(type(client.transport.create_function), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.create_function(request) @@ -1152,9 +1158,7 @@ async def test_create_function_field_headers_async(): request.location = "location/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_function), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1177,7 +1181,7 @@ def test_create_function_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_function), "__call__") as call: + with mock.patch.object(type(client.transport.create_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1220,9 +1224,7 @@ async def test_create_function_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1274,7 +1276,7 @@ def test_update_function( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_function), "__call__") as call: + with mock.patch.object(type(client.transport.update_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1295,19 +1297,19 @@ def test_update_function_from_dict(): @pytest.mark.asyncio -async def test_update_function_async(transport: str = "grpc_asyncio"): +async def test_update_function_async( + transport: str = "grpc_asyncio", request_type=functions.UpdateFunctionRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.UpdateFunctionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1319,12 +1321,17 @@ async def test_update_function_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.UpdateFunctionRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_update_function_async_from_dict(): + await test_update_function_async(request_type=dict) + + def test_update_function_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1336,7 +1343,7 @@ def test_update_function_field_headers(): request.function.name = "function.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_function), "__call__") as call: + with mock.patch.object(type(client.transport.update_function), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.update_function(request) @@ -1365,9 +1372,7 @@ async def test_update_function_field_headers_async(): request.function.name = "function.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_function), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1392,7 +1397,7 @@ def test_update_function_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_function), "__call__") as call: + with mock.patch.object(type(client.transport.update_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1429,9 +1434,7 @@ async def test_update_function_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1479,7 +1482,7 @@ def test_delete_function( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_function), "__call__") as call: + with mock.patch.object(type(client.transport.delete_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1500,19 +1503,19 @@ def test_delete_function_from_dict(): @pytest.mark.asyncio -async def test_delete_function_async(transport: str = "grpc_asyncio"): +async def test_delete_function_async( + transport: str = "grpc_asyncio", request_type=functions.DeleteFunctionRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.DeleteFunctionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1524,12 +1527,17 @@ async def test_delete_function_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.DeleteFunctionRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_delete_function_async_from_dict(): + await test_delete_function_async(request_type=dict) + + def test_delete_function_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1541,7 +1549,7 @@ def test_delete_function_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_function), "__call__") as call: + with mock.patch.object(type(client.transport.delete_function), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.delete_function(request) @@ -1568,9 +1576,7 @@ async def test_delete_function_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_function), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1593,7 +1599,7 @@ def test_delete_function_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_function), "__call__") as call: + with mock.patch.object(type(client.transport.delete_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1629,9 +1635,7 @@ async def test_delete_function_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1676,7 +1680,7 @@ def test_call_function( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.call_function), "__call__") as call: + with mock.patch.object(type(client.transport.call_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CallFunctionResponse( execution_id="execution_id_value", @@ -1693,6 +1697,7 @@ def test_call_function( assert args[0] == functions.CallFunctionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, functions.CallFunctionResponse) assert response.execution_id == "execution_id_value" @@ -1707,19 +1712,19 @@ def test_call_function_from_dict(): @pytest.mark.asyncio -async def test_call_function_async(transport: str = "grpc_asyncio"): +async def test_call_function_async( + transport: str = "grpc_asyncio", request_type=functions.CallFunctionRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.CallFunctionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.call_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.call_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.CallFunctionResponse( @@ -1735,7 +1740,7 @@ async def test_call_function_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.CallFunctionRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.CallFunctionResponse) @@ -1747,6 +1752,11 @@ async def test_call_function_async(transport: str = "grpc_asyncio"): assert response.error == "error_value" +@pytest.mark.asyncio +async def test_call_function_async_from_dict(): + await test_call_function_async(request_type=dict) + + def test_call_function_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1758,7 +1768,7 @@ def test_call_function_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.call_function), "__call__") as call: + with mock.patch.object(type(client.transport.call_function), "__call__") as call: call.return_value = functions.CallFunctionResponse() client.call_function(request) @@ -1785,9 +1795,7 @@ async def test_call_function_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.call_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.call_function), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.CallFunctionResponse() ) @@ -1810,7 +1818,7 @@ def test_call_function_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.call_function), "__call__") as call: + with mock.patch.object(type(client.transport.call_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CallFunctionResponse() @@ -1850,9 +1858,7 @@ async def test_call_function_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.call_function), "__call__" - ) as call: + with mock.patch.object(type(client.transport.call_function), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = functions.CallFunctionResponse() @@ -1900,7 +1906,7 @@ def test_generate_upload_url( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.generate_upload_url), "__call__" + type(client.transport.generate_upload_url), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = functions.GenerateUploadUrlResponse( @@ -1916,6 +1922,7 @@ def test_generate_upload_url( assert args[0] == functions.GenerateUploadUrlRequest() # Establish that the response is the type that we expect. + assert isinstance(response, functions.GenerateUploadUrlResponse) assert response.upload_url == "upload_url_value" @@ -1926,18 +1933,20 @@ def test_generate_upload_url_from_dict(): @pytest.mark.asyncio -async def test_generate_upload_url_async(transport: str = "grpc_asyncio"): +async def test_generate_upload_url_async( + transport: str = "grpc_asyncio", request_type=functions.GenerateUploadUrlRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.GenerateUploadUrlRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.generate_upload_url), "__call__" + type(client.transport.generate_upload_url), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1950,7 +1959,7 @@ async def test_generate_upload_url_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.GenerateUploadUrlRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.GenerateUploadUrlResponse) @@ -1958,6 +1967,11 @@ async def test_generate_upload_url_async(transport: str = "grpc_asyncio"): assert response.upload_url == "upload_url_value" +@pytest.mark.asyncio +async def test_generate_upload_url_async_from_dict(): + await test_generate_upload_url_async(request_type=dict) + + def test_generate_upload_url_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1970,7 +1984,7 @@ def test_generate_upload_url_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.generate_upload_url), "__call__" + type(client.transport.generate_upload_url), "__call__" ) as call: call.return_value = functions.GenerateUploadUrlResponse() @@ -1999,7 +2013,7 @@ async def test_generate_upload_url_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.generate_upload_url), "__call__" + type(client.transport.generate_upload_url), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.GenerateUploadUrlResponse() @@ -2030,7 +2044,7 @@ def test_generate_download_url( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.generate_download_url), "__call__" + type(client.transport.generate_download_url), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = functions.GenerateDownloadUrlResponse( @@ -2046,6 +2060,7 @@ def test_generate_download_url( assert args[0] == functions.GenerateDownloadUrlRequest() # Establish that the response is the type that we expect. + assert isinstance(response, functions.GenerateDownloadUrlResponse) assert response.download_url == "download_url_value" @@ -2056,18 +2071,20 @@ def test_generate_download_url_from_dict(): @pytest.mark.asyncio -async def test_generate_download_url_async(transport: str = "grpc_asyncio"): +async def test_generate_download_url_async( + transport: str = "grpc_asyncio", request_type=functions.GenerateDownloadUrlRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = functions.GenerateDownloadUrlRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.generate_download_url), "__call__" + type(client.transport.generate_download_url), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2080,7 +2097,7 @@ async def test_generate_download_url_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == functions.GenerateDownloadUrlRequest() # Establish that the response is the type that we expect. assert isinstance(response, functions.GenerateDownloadUrlResponse) @@ -2088,6 +2105,11 @@ async def test_generate_download_url_async(transport: str = "grpc_asyncio"): assert response.download_url == "download_url_value" +@pytest.mark.asyncio +async def test_generate_download_url_async_from_dict(): + await test_generate_download_url_async(request_type=dict) + + def test_generate_download_url_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2100,7 +2122,7 @@ def test_generate_download_url_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.generate_download_url), "__call__" + type(client.transport.generate_download_url), "__call__" ) as call: call.return_value = functions.GenerateDownloadUrlResponse() @@ -2129,7 +2151,7 @@ async def test_generate_download_url_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.generate_download_url), "__call__" + type(client.transport.generate_download_url), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( functions.GenerateDownloadUrlResponse() @@ -2159,7 +2181,7 @@ def test_set_iam_policy( request = request_type() # 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: + 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.Policy(version=774, etag=b"etag_blob",) @@ -2172,6 +2194,7 @@ def test_set_iam_policy( assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -2184,19 +2207,19 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_set_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = iam_policy.SetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + 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.Policy(version=774, etag=b"etag_blob",) @@ -2208,7 +2231,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -2218,6 +2241,11 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_set_iam_policy_async_from_dict(): + await test_set_iam_policy_async(request_type=dict) + + def test_set_iam_policy_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2229,7 +2257,7 @@ def test_set_iam_policy_field_headers(): request.resource = "resource/value" # 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: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.set_iam_policy(request) @@ -2256,9 +2284,7 @@ async def test_set_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.set_iam_policy(request) @@ -2273,12 +2299,12 @@ async def test_set_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_set_iam_policy_from_dict(): +def test_set_iam_policy_from_dict_foreign(): client = CloudFunctionsServiceClient( credentials=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: + 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.Policy() @@ -2303,7 +2329,7 @@ def test_get_iam_policy( request = request_type() # 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: + 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.Policy(version=774, etag=b"etag_blob",) @@ -2316,6 +2342,7 @@ def test_get_iam_policy( assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -2328,19 +2355,19 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_get_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = iam_policy.GetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + 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.Policy(version=774, etag=b"etag_blob",) @@ -2352,7 +2379,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -2362,6 +2389,11 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_get_iam_policy_async_from_dict(): + await test_get_iam_policy_async(request_type=dict) + + def test_get_iam_policy_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2373,7 +2405,7 @@ def test_get_iam_policy_field_headers(): request.resource = "resource/value" # 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: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.get_iam_policy(request) @@ -2400,9 +2432,7 @@ async def test_get_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.get_iam_policy(request) @@ -2417,12 +2447,12 @@ async def test_get_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_get_iam_policy_from_dict(): +def test_get_iam_policy_from_dict_foreign(): client = CloudFunctionsServiceClient( credentials=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: + 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.Policy() @@ -2448,7 +2478,7 @@ def test_test_iam_permissions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse( @@ -2464,6 +2494,7 @@ def test_test_iam_permissions( assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -2474,18 +2505,20 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio -async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): +async def test_test_iam_permissions_async( + transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest +): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = iam_policy.TestIamPermissionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2498,7 +2531,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, iam_policy.TestIamPermissionsResponse) @@ -2506,6 +2539,11 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert response.permissions == ["permissions_value"] +@pytest.mark.asyncio +async def test_test_iam_permissions_async_from_dict(): + await test_test_iam_permissions_async(request_type=dict) + + def test_test_iam_permissions_field_headers(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2518,7 +2556,7 @@ def test_test_iam_permissions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = iam_policy.TestIamPermissionsResponse() @@ -2547,7 +2585,7 @@ async def test_test_iam_permissions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( iam_policy.TestIamPermissionsResponse() @@ -2565,13 +2603,13 @@ async def test_test_iam_permissions_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_test_iam_permissions_from_dict(): +def test_test_iam_permissions_from_dict_foreign(): client = CloudFunctionsServiceClient( credentials=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__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -2621,7 +2659,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = CloudFunctionsServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2659,7 +2697,7 @@ def test_transport_grpc_default(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), ) - assert isinstance(client._transport, transports.CloudFunctionsServiceGrpcTransport,) + assert isinstance(client.transport, transports.CloudFunctionsServiceGrpcTransport,) def test_cloud_functions_service_base_transport_error(): @@ -2768,7 +2806,7 @@ def test_cloud_functions_service_host_no_port(): api_endpoint="cloudfunctions.googleapis.com" ), ) - assert client._transport._host == "cloudfunctions.googleapis.com:443" + assert client.transport._host == "cloudfunctions.googleapis.com:443" def test_cloud_functions_service_host_with_port(): @@ -2778,7 +2816,7 @@ def test_cloud_functions_service_host_with_port(): api_endpoint="cloudfunctions.googleapis.com:8000" ), ) - assert client._transport._host == "cloudfunctions.googleapis.com:8000" + assert client.transport._host == "cloudfunctions.googleapis.com:8000" def test_cloud_functions_service_grpc_transport_channel(): @@ -2790,6 +2828,7 @@ def test_cloud_functions_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_cloud_functions_service_grpc_asyncio_transport_channel(): @@ -2801,6 +2840,7 @@ def test_cloud_functions_service_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -2848,6 +2888,7 @@ def test_cloud_functions_service_transport_channel_mtls_with_client_cert_source( quota_project_id=None, ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2894,7 +2935,7 @@ def test_cloud_functions_service_grpc_lro_client(): client = CloudFunctionsServiceClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -2907,7 +2948,7 @@ def test_cloud_functions_service_grpc_lro_async_client(): client = CloudFunctionsServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -2943,6 +2984,107 @@ def test_parse_cloud_function_path(): assert expected == actual +def test_common_billing_account_path(): + billing_account = "cuttlefish" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = CloudFunctionsServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = CloudFunctionsServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = CloudFunctionsServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "winkle" + + expected = "folders/{folder}".format(folder=folder,) + actual = CloudFunctionsServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = CloudFunctionsServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = CloudFunctionsServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "scallop" + + expected = "organizations/{organization}".format(organization=organization,) + actual = CloudFunctionsServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = CloudFunctionsServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = CloudFunctionsServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "squid" + + expected = "projects/{project}".format(project=project,) + actual = CloudFunctionsServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = CloudFunctionsServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = CloudFunctionsServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "whelk" + location = "octopus" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = CloudFunctionsServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + } + path = CloudFunctionsServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = CloudFunctionsServiceClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo()