From bec9e87551baf9ef5d60c81810e3efa01e96377f Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 29 Dec 2020 12:19:25 -0800 Subject: [PATCH] fix: remove gRPC send/recv limits and expose client transport (#62) --- .flake8 | 1 + .kokoro/docker/docs/Dockerfile | 2 +- .kokoro/docs/common.cfg | 2 +- .kokoro/test-samples.sh | 8 +- .pre-commit-config.yaml | 17 + CODE_OF_CONDUCT.md | 123 ++++-- CONTRIBUTING.rst | 21 +- docs/conf.py | 7 +- docs/monitoring_v3/types.rst | 1 + .../alert_policy_service/async_client.py | 50 ++- .../services/alert_policy_service/client.py | 17 +- .../transports/__init__.py | 1 - .../alert_policy_service/transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 12 + .../services/group_service/async_client.py | 49 ++- .../services/group_service/client.py | 17 +- .../group_service/transports/__init__.py | 1 - .../services/group_service/transports/grpc.py | 28 +- .../group_service/transports/grpc_asyncio.py | 12 + .../services/metric_service/async_client.py | 144 +++---- .../services/metric_service/client.py | 122 +++--- .../metric_service/transports/__init__.py | 1 - .../metric_service/transports/grpc.py | 28 +- .../metric_service/transports/grpc_asyncio.py | 12 + .../async_client.py | 69 +-- .../notification_channel_service/client.py | 17 +- .../transports/__init__.py | 1 - .../transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 12 + .../async_client.py | 65 ++- .../service_monitoring_service/client.py | 17 +- .../transports/__init__.py | 1 - .../transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 12 + .../uptime_check_service/async_client.py | 50 ++- .../services/uptime_check_service/client.py | 17 +- .../transports/__init__.py | 1 - .../uptime_check_service/transports/grpc.py | 28 +- .../transports/grpc_asyncio.py | 12 + google/cloud/monitoring_v3/types/__init__.py | 9 +- google/cloud/monitoring_v3/types/metric.py | 2 +- google/cloud/monitoring_v3/types/service.py | 8 +- google/cloud/monitoring_v3/types/uptime.py | 2 +- noxfile.py | 11 +- samples/snippets/v3/alerts-client/noxfile.py | 39 +- samples/snippets/v3/cloud-client/noxfile.py | 39 +- .../v3/uptime-check-client/noxfile.py | 39 +- scripts/fixup_monitoring_v3_keywords.py | 1 + synth.metadata | 16 +- synth.py | 25 ++ .../test_alert_policy_service.py | 243 ++++++----- .../gapic/monitoring_v3/test_group_service.py | 298 +++++++------ .../monitoring_v3/test_metric_service.py | 387 +++++++++++------ .../test_notification_channel_service.py | 382 +++++++++------- .../test_service_monitoring_service.py | 407 ++++++++++-------- .../test_uptime_check_service.py | 263 ++++++----- 56 files changed, 2009 insertions(+), 1224 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 index ed931638..29227d4c 100644 --- a/.flake8 +++ b/.flake8 @@ -26,6 +26,7 @@ exclude = *_pb2.py # Standard linting exemptions. + **/.nox/** __pycache__, .git, *.pyc, diff --git a/.kokoro/docker/docs/Dockerfile b/.kokoro/docker/docs/Dockerfile index f4c0758c..412b0b56 100644 --- a/.kokoro/docker/docs/Dockerfile +++ b/.kokoro/docker/docs/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ubuntu:20.10 +from ubuntu:20.04 ENV DEBIAN_FRONTEND noninteractive diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index bad43f76..c5596761 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 56d48e0e..dbec4b51 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/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..a9024b15 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml +- repo: https://github.com/psf/black + rev: 19.10b0 + hooks: + - id: black +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b3d1f602..039f4368 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/CONTRIBUTING.rst b/CONTRIBUTING.rst index bf2f78be..f34dcc8e 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -21,8 +21,8 @@ In order to add a feature: - The feature must be documented in both the API and narrative documentation. -- The feature must work fully on the following CPython versions: 2.7, - 3.5, 3.6, 3.7 and 3.8 on both UNIX and Windows. +- The feature must work fully on the following CPython versions: + 3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows. - The feature must not add unnecessary dependencies (where "unnecessary" is of course subjective, but new dependencies should @@ -111,6 +111,16 @@ Coding Style should point to the official ``googleapis`` checkout and the the branch should be the main branch on that remote (``master``). +- This repository contains configuration for the + `pre-commit `__ tool, which automates checking + our linters during a commit. If you have it installed on your ``$PATH``, + you can enable enforcing those checks via: + +.. code-block:: bash + + $ pre-commit install + pre-commit installed at .git/hooks/pre-commit + Exceptions to PEP8: - Many unit tests use a helper method, ``_call_fut`` ("FUT" is short for @@ -192,25 +202,24 @@ Supported Python Versions We support: -- `Python 3.5`_ - `Python 3.6`_ - `Python 3.7`_ - `Python 3.8`_ +- `Python 3.9`_ -.. _Python 3.5: https://docs.python.org/3.5/ .. _Python 3.6: https://docs.python.org/3.6/ .. _Python 3.7: https://docs.python.org/3.7/ .. _Python 3.8: https://docs.python.org/3.8/ +.. _Python 3.9: https://docs.python.org/3.9/ Supported versions can be found in our ``noxfile.py`` `config`_. .. _config: https://github.com/googleapis/python-monitoring/blob/master/noxfile.py -Python 2.7 support is deprecated. All code changes should maintain Python 2.7 compatibility until January 1, 2020. We also explicitly decided to support Python 3 beginning with version -3.5. Reasons for this include: +3.6. Reasons for this include: - Encouraging use of newest versions of Python 3 - Taking the lead of `prominent`_ open-source `projects`_ diff --git a/docs/conf.py b/docs/conf.py index c283c715..2d0e39ca 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -345,10 +345,11 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "python": ("https://python.readthedocs.org/en/latest/", None), + "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), - "grpc": ("https://grpc.io/grpc/python/", None), + "grpc": ("https://grpc.github.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), } diff --git a/docs/monitoring_v3/types.rst b/docs/monitoring_v3/types.rst index 686802b5..ae49a858 100644 --- a/docs/monitoring_v3/types.rst +++ b/docs/monitoring_v3/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Monitoring v3 API .. automodule:: google.cloud.monitoring_v3.types :members: + :show-inheritance: diff --git a/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py b/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py index d03d1031..e853baab 100644 --- a/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py +++ b/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py @@ -69,16 +69,11 @@ class AlertPolicyServiceAsyncClient: AlertPolicyServiceClient.parse_alert_policy_condition_path ) - common_project_path = staticmethod(AlertPolicyServiceClient.common_project_path) - parse_common_project_path = staticmethod( - AlertPolicyServiceClient.parse_common_project_path - ) - - common_organization_path = staticmethod( - AlertPolicyServiceClient.common_organization_path + common_billing_account_path = staticmethod( + AlertPolicyServiceClient.common_billing_account_path ) - parse_common_organization_path = staticmethod( - AlertPolicyServiceClient.parse_common_organization_path + parse_common_billing_account_path = staticmethod( + AlertPolicyServiceClient.parse_common_billing_account_path ) common_folder_path = staticmethod(AlertPolicyServiceClient.common_folder_path) @@ -86,11 +81,16 @@ class AlertPolicyServiceAsyncClient: AlertPolicyServiceClient.parse_common_folder_path ) - common_billing_account_path = staticmethod( - AlertPolicyServiceClient.common_billing_account_path + common_organization_path = staticmethod( + AlertPolicyServiceClient.common_organization_path ) - parse_common_billing_account_path = staticmethod( - AlertPolicyServiceClient.parse_common_billing_account_path + parse_common_organization_path = staticmethod( + AlertPolicyServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(AlertPolicyServiceClient.common_project_path) + parse_common_project_path = staticmethod( + AlertPolicyServiceClient.parse_common_project_path ) common_location_path = staticmethod(AlertPolicyServiceClient.common_location_path) @@ -101,6 +101,15 @@ class AlertPolicyServiceAsyncClient: from_service_account_file = AlertPolicyServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> AlertPolicyServiceTransport: + """Return the transport used by the client instance. + + Returns: + AlertPolicyServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(AlertPolicyServiceClient).get_transport_class, type(AlertPolicyServiceClient), @@ -203,7 +212,8 @@ async def list_alert_policies( # 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." @@ -295,7 +305,8 @@ async def get_alert_policy( # 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." @@ -398,7 +409,8 @@ async def create_alert_policy( # 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, alert_policy]): + has_flattened_params = any([name, alert_policy]) + 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." @@ -471,7 +483,8 @@ async def delete_alert_policy( # 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." @@ -590,7 +603,8 @@ async def update_alert_policy( # 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([update_mask, alert_policy]): + has_flattened_params = any([update_mask, alert_policy]) + 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/monitoring_v3/services/alert_policy_service/client.py b/google/cloud/monitoring_v3/services/alert_policy_service/client.py index 5bd324d7..bea0a5fb 100644 --- a/google/cloud/monitoring_v3/services/alert_policy_service/client.py +++ b/google/cloud/monitoring_v3/services/alert_policy_service/client.py @@ -146,6 +146,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> AlertPolicyServiceTransport: + """Return the transport used by the client instance. + + Returns: + AlertPolicyServiceTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def alert_policy_path(project: str, alert_policy: str,) -> str: """Return a fully-qualified alert_policy string.""" @@ -273,10 +282,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/monitoring_v3/services/alert_policy_service/transports/__init__.py b/google/cloud/monitoring_v3/services/alert_policy_service/transports/__init__.py index 8044932e..64244d17 100644 --- a/google/cloud/monitoring_v3/services/alert_policy_service/transports/__init__.py +++ b/google/cloud/monitoring_v3/services/alert_policy_service/transports/__init__.py @@ -30,7 +30,6 @@ _transport_registry["grpc"] = AlertPolicyServiceGrpcTransport _transport_registry["grpc_asyncio"] = AlertPolicyServiceGrpcAsyncIOTransport - __all__ = ( "AlertPolicyServiceTransport", "AlertPolicyServiceGrpcTransport", diff --git a/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py b/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py index 069ab218..aa6fa157 100644 --- a/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py +++ b/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py @@ -99,10 +99,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: @@ -111,6 +111,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. @@ -118,6 +120,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", @@ -153,7 +156,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -170,6 +178,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] @@ -196,7 +208,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -231,12 +243,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/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py b/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py index 82ca5a67..e17d9242 100644 --- a/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py @@ -156,6 +156,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. @@ -163,6 +165,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", @@ -198,7 +201,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -215,6 +223,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. diff --git a/google/cloud/monitoring_v3/services/group_service/async_client.py b/google/cloud/monitoring_v3/services/group_service/async_client.py index b9b7a048..50e2f97f 100644 --- a/google/cloud/monitoring_v3/services/group_service/async_client.py +++ b/google/cloud/monitoring_v3/services/group_service/async_client.py @@ -62,24 +62,24 @@ class GroupServiceAsyncClient: group_path = staticmethod(GroupServiceClient.group_path) parse_group_path = staticmethod(GroupServiceClient.parse_group_path) - common_project_path = staticmethod(GroupServiceClient.common_project_path) - parse_common_project_path = staticmethod( - GroupServiceClient.parse_common_project_path + common_billing_account_path = staticmethod( + GroupServiceClient.common_billing_account_path ) - - common_organization_path = staticmethod(GroupServiceClient.common_organization_path) - parse_common_organization_path = staticmethod( - GroupServiceClient.parse_common_organization_path + parse_common_billing_account_path = staticmethod( + GroupServiceClient.parse_common_billing_account_path ) common_folder_path = staticmethod(GroupServiceClient.common_folder_path) parse_common_folder_path = staticmethod(GroupServiceClient.parse_common_folder_path) - common_billing_account_path = staticmethod( - GroupServiceClient.common_billing_account_path + common_organization_path = staticmethod(GroupServiceClient.common_organization_path) + parse_common_organization_path = staticmethod( + GroupServiceClient.parse_common_organization_path ) - parse_common_billing_account_path = staticmethod( - GroupServiceClient.parse_common_billing_account_path + + common_project_path = staticmethod(GroupServiceClient.common_project_path) + parse_common_project_path = staticmethod( + GroupServiceClient.parse_common_project_path ) common_location_path = staticmethod(GroupServiceClient.common_location_path) @@ -90,6 +90,15 @@ class GroupServiceAsyncClient: from_service_account_file = GroupServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> GroupServiceTransport: + """Return the transport used by the client instance. + + Returns: + GroupServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(GroupServiceClient).get_transport_class, type(GroupServiceClient) ) @@ -184,7 +193,8 @@ async def list_groups( # 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." @@ -302,7 +312,8 @@ async def get_group( # 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." @@ -422,7 +433,8 @@ async def create_group( # 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, group]): + has_flattened_params = any([name, group]) + 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." @@ -527,7 +539,8 @@ async def update_group( # 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([group]): + has_flattened_params = any([group]) + 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." @@ -606,7 +619,8 @@ async def delete_group( # 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." @@ -690,7 +704,8 @@ async def list_group_members( # 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." diff --git a/google/cloud/monitoring_v3/services/group_service/client.py b/google/cloud/monitoring_v3/services/group_service/client.py index 461fc805..18017fee 100644 --- a/google/cloud/monitoring_v3/services/group_service/client.py +++ b/google/cloud/monitoring_v3/services/group_service/client.py @@ -143,6 +143,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> GroupServiceTransport: + """Return the transport used by the client instance. + + Returns: + GroupServiceTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def group_path(project: str, group: str,) -> str: """Return a fully-qualified group string.""" @@ -248,10 +257,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/monitoring_v3/services/group_service/transports/__init__.py b/google/cloud/monitoring_v3/services/group_service/transports/__init__.py index 93adbcbe..12ae8abb 100644 --- a/google/cloud/monitoring_v3/services/group_service/transports/__init__.py +++ b/google/cloud/monitoring_v3/services/group_service/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = GroupServiceGrpcTransport _transport_registry["grpc_asyncio"] = GroupServiceGrpcAsyncIOTransport - __all__ = ( "GroupServiceTransport", "GroupServiceGrpcTransport", diff --git a/google/cloud/monitoring_v3/services/group_service/transports/grpc.py b/google/cloud/monitoring_v3/services/group_service/transports/grpc.py index c085fff0..a61c89e5 100644 --- a/google/cloud/monitoring_v3/services/group_service/transports/grpc.py +++ b/google/cloud/monitoring_v3/services/group_service/transports/grpc.py @@ -103,10 +103,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: @@ -115,6 +115,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. @@ -122,6 +124,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", @@ -157,7 +160,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -174,6 +182,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] @@ -200,7 +212,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -235,12 +247,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/monitoring_v3/services/group_service/transports/grpc_asyncio.py b/google/cloud/monitoring_v3/services/group_service/transports/grpc_asyncio.py index 1c66dd37..ffda52bb 100644 --- a/google/cloud/monitoring_v3/services/group_service/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_v3/services/group_service/transports/grpc_asyncio.py @@ -160,6 +160,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. @@ -167,6 +169,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", @@ -202,7 +205,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -219,6 +227,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. diff --git a/google/cloud/monitoring_v3/services/metric_service/async_client.py b/google/cloud/monitoring_v3/services/metric_service/async_client.py index 08151a08..bb8c9da4 100644 --- a/google/cloud/monitoring_v3/services/metric_service/async_client.py +++ b/google/cloud/monitoring_v3/services/metric_service/async_client.py @@ -52,16 +52,20 @@ class MetricServiceAsyncClient: DEFAULT_ENDPOINT = MetricServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = MetricServiceClient.DEFAULT_MTLS_ENDPOINT - common_project_path = staticmethod(MetricServiceClient.common_project_path) - parse_common_project_path = staticmethod( - MetricServiceClient.parse_common_project_path + """metric_descriptor_path = staticmethod(MetricServiceClient.metric_descriptor_path) + parse_metric_descriptor_path = staticmethod(MetricServiceClient.parse_metric_descriptor_path)""" + monitored_resource_descriptor_path = staticmethod( + MetricServiceClient.monitored_resource_descriptor_path + ) + parse_monitored_resource_descriptor_path = staticmethod( + MetricServiceClient.parse_monitored_resource_descriptor_path ) - common_organization_path = staticmethod( - MetricServiceClient.common_organization_path + common_billing_account_path = staticmethod( + MetricServiceClient.common_billing_account_path ) - parse_common_organization_path = staticmethod( - MetricServiceClient.parse_common_organization_path + parse_common_billing_account_path = staticmethod( + MetricServiceClient.parse_common_billing_account_path ) common_folder_path = staticmethod(MetricServiceClient.common_folder_path) @@ -69,11 +73,16 @@ class MetricServiceAsyncClient: MetricServiceClient.parse_common_folder_path ) - common_billing_account_path = staticmethod( - MetricServiceClient.common_billing_account_path + common_organization_path = staticmethod( + MetricServiceClient.common_organization_path ) - parse_common_billing_account_path = staticmethod( - MetricServiceClient.parse_common_billing_account_path + parse_common_organization_path = staticmethod( + MetricServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(MetricServiceClient.common_project_path) + parse_common_project_path = staticmethod( + MetricServiceClient.parse_common_project_path ) common_location_path = staticmethod(MetricServiceClient.common_location_path) @@ -84,6 +93,15 @@ class MetricServiceAsyncClient: from_service_account_file = MetricServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> MetricServiceTransport: + """Return the transport used by the client instance. + + Returns: + MetricServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(MetricServiceClient).get_transport_class, type(MetricServiceClient) ) @@ -180,7 +198,8 @@ async def list_monitored_resource_descriptors( # 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." @@ -274,33 +293,17 @@ async def get_monitored_resource_descriptor( specifies the use of the labels ``"instance_id"`` and ``"zone"`` to identify particular VM instances. - Different services can support different monitored - resource types. - - The following are specific rules to service defined - monitored resources for Monitoring and Logging: - - - The ``type``, ``display_name``, ``description``, - ``labels`` and ``launch_stage`` fields are all - required. - - The first label of the monitored resource descriptor - must be ``resource_container``. There are legacy - monitored resource descritptors start with - ``project_id``. - - It must include a ``location`` label. - - Maximum of default 5 service defined monitored - resource descriptors is allowed per service. - - Maximum of default 10 labels per monitored resource - is allowed. - - The default maximum limit can be overridden. Please - follow https://cloud.google.com/monitoring/quotas + Different APIs can support different monitored resource + types. APIs generally provide a ``list`` method that + returns the monitored resource descriptors used by the + API. """ # 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." @@ -385,7 +388,8 @@ async def list_metric_descriptors( # 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." @@ -470,32 +474,18 @@ async def get_metric_descriptor( Returns: ~.ga_metric.MetricDescriptor: - Defines a metric type and its schema. Once a metric - descriptor is created, deleting or altering it stops - data collection and makes the metric type's existing - data unusable. - - The following are specific rules for service defined - Monitoring metric descriptors: - - - ``type``, ``metric_kind``, ``value_type``, - ``description``, ``display_name``, ``launch_stage`` - fields are all required. The ``unit`` field must be - specified if the ``value_type`` is any of DOUBLE, - INT64, DISTRIBUTION. - - Maximum of default 500 metric descriptors per service - is allowed. - - Maximum of default 10 labels per metric descriptor is - allowed. - - The default maximum limit can be overridden. Please - follow https://cloud.google.com/monitoring/quotas + Defines a metric type and its schema. + Once a metric descriptor is created, + deleting or altering it stops data + collection and makes the metric type's + existing data unusable. """ # 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." @@ -581,32 +571,18 @@ async def create_metric_descriptor( Returns: ~.ga_metric.MetricDescriptor: - Defines a metric type and its schema. Once a metric - descriptor is created, deleting or altering it stops - data collection and makes the metric type's existing - data unusable. - - The following are specific rules for service defined - Monitoring metric descriptors: - - - ``type``, ``metric_kind``, ``value_type``, - ``description``, ``display_name``, ``launch_stage`` - fields are all required. The ``unit`` field must be - specified if the ``value_type`` is any of DOUBLE, - INT64, DISTRIBUTION. - - Maximum of default 500 metric descriptors per service - is allowed. - - Maximum of default 10 labels per metric descriptor is - allowed. - - The default maximum limit can be overridden. Please - follow https://cloud.google.com/monitoring/quotas + Defines a metric type and its schema. + Once a metric descriptor is created, + deleting or altering it stops data + collection and makes the metric type's + existing data unusable. """ # 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, metric_descriptor]): + has_flattened_params = any([name, metric_descriptor]) + 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." @@ -682,7 +658,8 @@ async def delete_metric_descriptor( # 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." @@ -799,7 +776,8 @@ async def list_time_series( # 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, filter, interval, view]): + has_flattened_params = any([name, filter, interval, view]) + 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." @@ -906,7 +884,8 @@ async def create_time_series( # 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, time_series]): + has_flattened_params = any([name, time_series]) + 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." @@ -919,8 +898,9 @@ async def create_time_series( if name is not None: request.name = name - if time_series is not None: - request.time_series = time_series + + if time_series: + request.time_series.extend(time_series) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/monitoring_v3/services/metric_service/client.py b/google/cloud/monitoring_v3/services/metric_service/client.py index 68645bff..3cdacc94 100644 --- a/google/cloud/monitoring_v3/services/metric_service/client.py +++ b/google/cloud/monitoring_v3/services/metric_service/client.py @@ -136,6 +136,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> MetricServiceTransport: + """Return the transport used by the client instance. + + Returns: + MetricServiceTransport: The transport used by the client instance. + """ + return self._transport + + '''@staticmethod + def metric_descriptor_path(project: str,) -> str: + """Return a fully-qualified metric_descriptor string.""" + return "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(project=project, ) + + @staticmethod + def parse_metric_descriptor_path(path: str) -> Dict[str,str]: + """Parse a metric_descriptor path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/metricDescriptors/{metric_descriptor=**}$", path) + return m.groupdict() if m else {}''' + + @staticmethod + def monitored_resource_descriptor_path( + project: str, monitored_resource_descriptor: str, + ) -> str: + """Return a fully-qualified monitored_resource_descriptor string.""" + return "projects/{project}/monitoredResourceDescriptors/{monitored_resource_descriptor}".format( + project=project, + monitored_resource_descriptor=monitored_resource_descriptor, + ) + + @staticmethod + def parse_monitored_resource_descriptor_path(path: str) -> Dict[str, str]: + """Parse a monitored_resource_descriptor path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/monitoredResourceDescriptors/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def common_billing_account_path(billing_account: str,) -> str: """Return a fully-qualified billing_account string.""" @@ -230,10 +269,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: @@ -448,27 +487,10 @@ def get_monitored_resource_descriptor( specifies the use of the labels ``"instance_id"`` and ``"zone"`` to identify particular VM instances. - Different services can support different monitored - resource types. - - The following are specific rules to service defined - monitored resources for Monitoring and Logging: - - - The ``type``, ``display_name``, ``description``, - ``labels`` and ``launch_stage`` fields are all - required. - - The first label of the monitored resource descriptor - must be ``resource_container``. There are legacy - monitored resource descritptors start with - ``project_id``. - - It must include a ``location`` label. - - Maximum of default 5 service defined monitored - resource descriptors is allowed per service. - - Maximum of default 10 labels per monitored resource - is allowed. - - The default maximum limit can be overridden. Please - follow https://cloud.google.com/monitoring/quotas + Different APIs can support different monitored resource + types. APIs generally provide a ``list`` method that + returns the monitored resource descriptors used by the + API. """ # Create or coerce a protobuf request object. @@ -636,26 +658,11 @@ def get_metric_descriptor( Returns: ~.ga_metric.MetricDescriptor: - Defines a metric type and its schema. Once a metric - descriptor is created, deleting or altering it stops - data collection and makes the metric type's existing - data unusable. - - The following are specific rules for service defined - Monitoring metric descriptors: - - - ``type``, ``metric_kind``, ``value_type``, - ``description``, ``display_name``, ``launch_stage`` - fields are all required. The ``unit`` field must be - specified if the ``value_type`` is any of DOUBLE, - INT64, DISTRIBUTION. - - Maximum of default 500 metric descriptors per service - is allowed. - - Maximum of default 10 labels per metric descriptor is - allowed. - - The default maximum limit can be overridden. Please - follow https://cloud.google.com/monitoring/quotas + Defines a metric type and its schema. + Once a metric descriptor is created, + deleting or altering it stops data + collection and makes the metric type's + existing data unusable. """ # Create or coerce a protobuf request object. @@ -741,26 +748,11 @@ def create_metric_descriptor( Returns: ~.ga_metric.MetricDescriptor: - Defines a metric type and its schema. Once a metric - descriptor is created, deleting or altering it stops - data collection and makes the metric type's existing - data unusable. - - The following are specific rules for service defined - Monitoring metric descriptors: - - - ``type``, ``metric_kind``, ``value_type``, - ``description``, ``display_name``, ``launch_stage`` - fields are all required. The ``unit`` field must be - specified if the ``value_type`` is any of DOUBLE, - INT64, DISTRIBUTION. - - Maximum of default 500 metric descriptors per service - is allowed. - - Maximum of default 10 labels per metric descriptor is - allowed. - - The default maximum limit can be overridden. Please - follow https://cloud.google.com/monitoring/quotas + Defines a metric type and its schema. + Once a metric descriptor is created, + deleting or altering it stops data + collection and makes the metric type's + existing data unusable. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/monitoring_v3/services/metric_service/transports/__init__.py b/google/cloud/monitoring_v3/services/metric_service/transports/__init__.py index 1fd84db5..943ac0a8 100644 --- a/google/cloud/monitoring_v3/services/metric_service/transports/__init__.py +++ b/google/cloud/monitoring_v3/services/metric_service/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = MetricServiceGrpcTransport _transport_registry["grpc_asyncio"] = MetricServiceGrpcAsyncIOTransport - __all__ = ( "MetricServiceTransport", "MetricServiceGrpcTransport", diff --git a/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py b/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py index 914057fe..5df95042 100644 --- a/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py +++ b/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py @@ -93,10 +93,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: @@ -105,6 +105,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. @@ -112,6 +114,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", @@ -147,7 +150,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -164,6 +172,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] @@ -190,7 +202,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -225,12 +237,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/monitoring_v3/services/metric_service/transports/grpc_asyncio.py b/google/cloud/monitoring_v3/services/metric_service/transports/grpc_asyncio.py index b03e4b1e..e5a2df2e 100644 --- a/google/cloud/monitoring_v3/services/metric_service/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_v3/services/metric_service/transports/grpc_asyncio.py @@ -150,6 +150,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. @@ -157,6 +159,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", @@ -192,7 +195,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -209,6 +217,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. diff --git a/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py b/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py index ac7d9569..1f15c4cb 100644 --- a/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py +++ b/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py @@ -66,18 +66,11 @@ class NotificationChannelServiceAsyncClient: NotificationChannelServiceClient.parse_notification_channel_descriptor_path ) - common_project_path = staticmethod( - NotificationChannelServiceClient.common_project_path - ) - parse_common_project_path = staticmethod( - NotificationChannelServiceClient.parse_common_project_path - ) - - common_organization_path = staticmethod( - NotificationChannelServiceClient.common_organization_path + common_billing_account_path = staticmethod( + NotificationChannelServiceClient.common_billing_account_path ) - parse_common_organization_path = staticmethod( - NotificationChannelServiceClient.parse_common_organization_path + parse_common_billing_account_path = staticmethod( + NotificationChannelServiceClient.parse_common_billing_account_path ) common_folder_path = staticmethod( @@ -87,11 +80,18 @@ class NotificationChannelServiceAsyncClient: NotificationChannelServiceClient.parse_common_folder_path ) - common_billing_account_path = staticmethod( - NotificationChannelServiceClient.common_billing_account_path + common_organization_path = staticmethod( + NotificationChannelServiceClient.common_organization_path ) - parse_common_billing_account_path = staticmethod( - NotificationChannelServiceClient.parse_common_billing_account_path + parse_common_organization_path = staticmethod( + NotificationChannelServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod( + NotificationChannelServiceClient.common_project_path + ) + parse_common_project_path = staticmethod( + NotificationChannelServiceClient.parse_common_project_path ) common_location_path = staticmethod( @@ -106,6 +106,15 @@ class NotificationChannelServiceAsyncClient: ) from_service_account_json = from_service_account_file + @property + def transport(self) -> NotificationChannelServiceTransport: + """Return the transport used by the client instance. + + Returns: + NotificationChannelServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(NotificationChannelServiceClient).get_transport_class, type(NotificationChannelServiceClient), @@ -211,7 +220,8 @@ async def list_notification_channel_descriptors( # 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." @@ -307,7 +317,8 @@ async def get_notification_channel_descriptor( # 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." @@ -400,7 +411,8 @@ async def list_notification_channels( # 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." @@ -499,7 +511,8 @@ async def get_notification_channel( # 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." @@ -602,7 +615,8 @@ async def create_notification_channel( # 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, notification_channel]): + has_flattened_params = any([name, notification_channel]) + 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." @@ -689,7 +703,8 @@ async def update_notification_channel( # 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([update_mask, notification_channel]): + has_flattened_params = any([update_mask, notification_channel]) + 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." @@ -775,7 +790,8 @@ async def delete_notification_channel( # 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, force]): + has_flattened_params = any([name, force]) + 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." @@ -851,7 +867,8 @@ async def send_notification_channel_verification_code( # 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." @@ -952,7 +969,8 @@ async def get_notification_channel_verification_code( # 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." @@ -1053,7 +1071,8 @@ async def verify_notification_channel( # 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, code]): + has_flattened_params = any([name, code]) + 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/monitoring_v3/services/notification_channel_service/client.py b/google/cloud/monitoring_v3/services/notification_channel_service/client.py index b8feecbe..3b1ffe37 100644 --- a/google/cloud/monitoring_v3/services/notification_channel_service/client.py +++ b/google/cloud/monitoring_v3/services/notification_channel_service/client.py @@ -141,6 +141,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> NotificationChannelServiceTransport: + """Return the transport used by the client instance. + + Returns: + NotificationChannelServiceTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def notification_channel_path(project: str, notification_channel: str,) -> str: """Return a fully-qualified notification_channel string.""" @@ -269,10 +278,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/monitoring_v3/services/notification_channel_service/transports/__init__.py b/google/cloud/monitoring_v3/services/notification_channel_service/transports/__init__.py index 5c9458a1..3b8843d6 100644 --- a/google/cloud/monitoring_v3/services/notification_channel_service/transports/__init__.py +++ b/google/cloud/monitoring_v3/services/notification_channel_service/transports/__init__.py @@ -30,7 +30,6 @@ _transport_registry["grpc"] = NotificationChannelServiceGrpcTransport _transport_registry["grpc_asyncio"] = NotificationChannelServiceGrpcAsyncIOTransport - __all__ = ( "NotificationChannelServiceTransport", "NotificationChannelServiceGrpcTransport", diff --git a/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py b/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py index 8d26d140..808434bb 100644 --- a/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py +++ b/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py @@ -92,10 +92,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: @@ -104,6 +104,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. @@ -111,6 +113,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", @@ -146,7 +149,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -163,6 +171,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] @@ -189,7 +201,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -224,12 +236,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/monitoring_v3/services/notification_channel_service/transports/grpc_asyncio.py b/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc_asyncio.py index 7216be8e..14eb7a95 100644 --- a/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_v3/services/notification_channel_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", @@ -193,7 +196,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -210,6 +218,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. diff --git a/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py b/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py index c3a53f7a..839e9f16 100644 --- a/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py +++ b/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py @@ -61,11 +61,16 @@ class ServiceMonitoringServiceAsyncClient: ServiceMonitoringServiceClient.parse_service_level_objective_path ) - common_project_path = staticmethod( - ServiceMonitoringServiceClient.common_project_path + common_billing_account_path = staticmethod( + ServiceMonitoringServiceClient.common_billing_account_path ) - parse_common_project_path = staticmethod( - ServiceMonitoringServiceClient.parse_common_project_path + parse_common_billing_account_path = staticmethod( + ServiceMonitoringServiceClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(ServiceMonitoringServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + ServiceMonitoringServiceClient.parse_common_folder_path ) common_organization_path = staticmethod( @@ -75,16 +80,11 @@ class ServiceMonitoringServiceAsyncClient: ServiceMonitoringServiceClient.parse_common_organization_path ) - common_folder_path = staticmethod(ServiceMonitoringServiceClient.common_folder_path) - parse_common_folder_path = staticmethod( - ServiceMonitoringServiceClient.parse_common_folder_path - ) - - common_billing_account_path = staticmethod( - ServiceMonitoringServiceClient.common_billing_account_path + common_project_path = staticmethod( + ServiceMonitoringServiceClient.common_project_path ) - parse_common_billing_account_path = staticmethod( - ServiceMonitoringServiceClient.parse_common_billing_account_path + parse_common_project_path = staticmethod( + ServiceMonitoringServiceClient.parse_common_project_path ) common_location_path = staticmethod( @@ -97,6 +97,15 @@ class ServiceMonitoringServiceAsyncClient: from_service_account_file = ServiceMonitoringServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> ServiceMonitoringServiceTransport: + """Return the transport used by the client instance. + + Returns: + ServiceMonitoringServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(ServiceMonitoringServiceClient).get_transport_class, type(ServiceMonitoringServiceClient), @@ -201,7 +210,8 @@ async def create_service( # 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([parent, service]): + has_flattened_params = any([parent, service]) + 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." @@ -282,7 +292,8 @@ async def get_service( # 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." @@ -368,7 +379,8 @@ async def list_services( # 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([parent]): + has_flattened_params = any([parent]) + 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." @@ -457,7 +469,8 @@ async def update_service( # 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([service]): + has_flattened_params = any([service]) + 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." @@ -527,7 +540,8 @@ async def delete_service( # 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." @@ -628,7 +642,8 @@ async def create_service_level_objective( # 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([parent, service_level_objective]): + has_flattened_params = any([parent, service_level_objective]) + 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." @@ -716,7 +731,8 @@ async def get_service_level_objective( # 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." @@ -803,7 +819,8 @@ async def list_service_level_objectives( # 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([parent]): + has_flattened_params = any([parent]) + 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." @@ -900,7 +917,8 @@ async def update_service_level_objective( # 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([service_level_objective]): + has_flattened_params = any([service_level_objective]) + 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." @@ -976,7 +994,8 @@ async def delete_service_level_objective( # 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." diff --git a/google/cloud/monitoring_v3/services/service_monitoring_service/client.py b/google/cloud/monitoring_v3/services/service_monitoring_service/client.py index cfbe98d1..e5837ba6 100644 --- a/google/cloud/monitoring_v3/services/service_monitoring_service/client.py +++ b/google/cloud/monitoring_v3/services/service_monitoring_service/client.py @@ -140,6 +140,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> ServiceMonitoringServiceTransport: + """Return the transport used by the client instance. + + Returns: + ServiceMonitoringServiceTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def service_path(project: str, service: str,) -> str: """Return a fully-qualified service string.""" @@ -267,10 +276,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/monitoring_v3/services/service_monitoring_service/transports/__init__.py b/google/cloud/monitoring_v3/services/service_monitoring_service/transports/__init__.py index ae774881..ce9d3d3d 100644 --- a/google/cloud/monitoring_v3/services/service_monitoring_service/transports/__init__.py +++ b/google/cloud/monitoring_v3/services/service_monitoring_service/transports/__init__.py @@ -30,7 +30,6 @@ _transport_registry["grpc"] = ServiceMonitoringServiceGrpcTransport _transport_registry["grpc_asyncio"] = ServiceMonitoringServiceGrpcAsyncIOTransport - __all__ = ( "ServiceMonitoringServiceTransport", "ServiceMonitoringServiceGrpcTransport", diff --git a/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py b/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py index a6e4b552..e6a650e1 100644 --- a/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py +++ b/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py @@ -95,10 +95,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: @@ -107,6 +107,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. @@ -114,6 +116,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,7 +152,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -166,6 +174,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] @@ -192,7 +204,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -227,12 +239,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/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py b/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py index 8614483f..19c95873 100644 --- a/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py @@ -152,6 +152,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. @@ -159,6 +161,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,7 +197,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -211,6 +219,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. diff --git a/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py b/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py index 7e52209c..e01a219d 100644 --- a/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py +++ b/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py @@ -62,16 +62,11 @@ class UptimeCheckServiceAsyncClient: UptimeCheckServiceClient.parse_uptime_check_config_path ) - common_project_path = staticmethod(UptimeCheckServiceClient.common_project_path) - parse_common_project_path = staticmethod( - UptimeCheckServiceClient.parse_common_project_path - ) - - common_organization_path = staticmethod( - UptimeCheckServiceClient.common_organization_path + common_billing_account_path = staticmethod( + UptimeCheckServiceClient.common_billing_account_path ) - parse_common_organization_path = staticmethod( - UptimeCheckServiceClient.parse_common_organization_path + parse_common_billing_account_path = staticmethod( + UptimeCheckServiceClient.parse_common_billing_account_path ) common_folder_path = staticmethod(UptimeCheckServiceClient.common_folder_path) @@ -79,11 +74,16 @@ class UptimeCheckServiceAsyncClient: UptimeCheckServiceClient.parse_common_folder_path ) - common_billing_account_path = staticmethod( - UptimeCheckServiceClient.common_billing_account_path + common_organization_path = staticmethod( + UptimeCheckServiceClient.common_organization_path ) - parse_common_billing_account_path = staticmethod( - UptimeCheckServiceClient.parse_common_billing_account_path + parse_common_organization_path = staticmethod( + UptimeCheckServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(UptimeCheckServiceClient.common_project_path) + parse_common_project_path = staticmethod( + UptimeCheckServiceClient.parse_common_project_path ) common_location_path = staticmethod(UptimeCheckServiceClient.common_location_path) @@ -94,6 +94,15 @@ class UptimeCheckServiceAsyncClient: from_service_account_file = UptimeCheckServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> UptimeCheckServiceTransport: + """Return the transport used by the client instance. + + Returns: + UptimeCheckServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(UptimeCheckServiceClient).get_transport_class, type(UptimeCheckServiceClient), @@ -193,7 +202,8 @@ async def list_uptime_check_configs( # 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([parent]): + has_flattened_params = any([parent]) + 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." @@ -283,7 +293,8 @@ async def get_uptime_check_config( # 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." @@ -374,7 +385,8 @@ async def create_uptime_check_config( # 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([parent, uptime_check_config]): + has_flattened_params = any([parent, uptime_check_config]) + 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." @@ -463,7 +475,8 @@ async def update_uptime_check_config( # 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([uptime_check_config]): + has_flattened_params = any([uptime_check_config]) + 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." @@ -537,7 +550,8 @@ async def delete_uptime_check_config( # 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." diff --git a/google/cloud/monitoring_v3/services/uptime_check_service/client.py b/google/cloud/monitoring_v3/services/uptime_check_service/client.py index 72a0f3e8..be375a82 100644 --- a/google/cloud/monitoring_v3/services/uptime_check_service/client.py +++ b/google/cloud/monitoring_v3/services/uptime_check_service/client.py @@ -143,6 +143,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> UptimeCheckServiceTransport: + """Return the transport used by the client instance. + + Returns: + UptimeCheckServiceTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def uptime_check_config_path(project: str, uptime_check_config: str,) -> str: """Return a fully-qualified uptime_check_config string.""" @@ -253,10 +262,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/monitoring_v3/services/uptime_check_service/transports/__init__.py b/google/cloud/monitoring_v3/services/uptime_check_service/transports/__init__.py index 5f21c445..bfe3276f 100644 --- a/google/cloud/monitoring_v3/services/uptime_check_service/transports/__init__.py +++ b/google/cloud/monitoring_v3/services/uptime_check_service/transports/__init__.py @@ -30,7 +30,6 @@ _transport_registry["grpc"] = UptimeCheckServiceGrpcTransport _transport_registry["grpc_asyncio"] = UptimeCheckServiceGrpcAsyncIOTransport - __all__ = ( "UptimeCheckServiceTransport", "UptimeCheckServiceGrpcTransport", diff --git a/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py b/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py index 3d27be4d..8143b5b7 100644 --- a/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py +++ b/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py @@ -98,10 +98,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: @@ -110,6 +110,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. @@ -117,6 +119,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", @@ -152,7 +155,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -169,6 +177,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] @@ -195,7 +207,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -230,12 +242,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/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py b/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py index 7f5a7575..06aa444d 100644 --- a/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py +++ b/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py @@ -155,6 +155,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. @@ -162,6 +164,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", @@ -197,7 +200,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -214,6 +222,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. diff --git a/google/cloud/monitoring_v3/types/__init__.py b/google/cloud/monitoring_v3/types/__init__.py index 51d7a273..6ee5ca44 100644 --- a/google/cloud/monitoring_v3/types/__init__.py +++ b/google/cloud/monitoring_v3/types/__init__.py @@ -19,6 +19,8 @@ TypedValue, TimeInterval, Aggregation, + ComparisonType, + ServiceTier, ) from .mutation_record import MutationRecord from .alert import AlertPolicy @@ -118,6 +120,8 @@ InternalChecker, UptimeCheckConfig, UptimeCheckIp, + UptimeCheckRegion, + GroupResourceType, ) from .uptime_service import ( ListUptimeCheckConfigsRequest, @@ -130,11 +134,12 @@ ListUptimeCheckIpsResponse, ) - __all__ = ( "TypedValue", "TimeInterval", "Aggregation", + "ComparisonType", + "ServiceTier", "MutationRecord", "AlertPolicy", "CreateAlertPolicyRequest", @@ -216,6 +221,8 @@ "InternalChecker", "UptimeCheckConfig", "UptimeCheckIp", + "UptimeCheckRegion", + "GroupResourceType", "ListUptimeCheckConfigsRequest", "ListUptimeCheckConfigsResponse", "GetUptimeCheckConfigRequest", diff --git a/google/cloud/monitoring_v3/types/metric.py b/google/cloud/monitoring_v3/types/metric.py index ee7a133e..1c4b8494 100644 --- a/google/cloud/monitoring_v3/types/metric.py +++ b/google/cloud/monitoring_v3/types/metric.py @@ -135,7 +135,7 @@ class TimeSeries(proto.Message): proto.ENUM, number=4, enum=ga_metric.MetricDescriptor.ValueType, ) - points = proto.RepeatedField(proto.MESSAGE, number=5, message=Point,) + points = proto.RepeatedField(proto.MESSAGE, number=5, message="Point",) class TimeSeriesDescriptor(proto.Message): diff --git a/google/cloud/monitoring_v3/types/service.py b/google/cloud/monitoring_v3/types/service.py index 755c90dc..728cacd4 100644 --- a/google/cloud/monitoring_v3/types/service.py +++ b/google/cloud/monitoring_v3/types/service.py @@ -479,7 +479,7 @@ class DistributionCut(proto.Message): distribution_filter = proto.Field(proto.STRING, number=4) - range_ = proto.Field(proto.MESSAGE, number=5, message=Range,) + range_ = proto.Field(proto.MESSAGE, number=5, message="Range",) class WindowsBasedSli(proto.Message): @@ -522,11 +522,11 @@ class PerformanceThreshold(proto.Message): """ performance = proto.Field( - proto.MESSAGE, number=1, oneof="type", message=RequestBasedSli, + proto.MESSAGE, number=1, oneof="type", message="RequestBasedSli", ) basic_sli_performance = proto.Field( - proto.MESSAGE, number=3, oneof="type", message=BasicSli, + proto.MESSAGE, number=3, oneof="type", message="BasicSli", ) threshold = proto.Field(proto.DOUBLE, number=2) @@ -550,7 +550,7 @@ class MetricRange(proto.Message): time_series = proto.Field(proto.STRING, number=1) - range_ = proto.Field(proto.MESSAGE, number=4, message=Range,) + range_ = proto.Field(proto.MESSAGE, number=4, message="Range",) good_bad_metric_filter = proto.Field( proto.STRING, number=5, oneof="window_criterion" diff --git a/google/cloud/monitoring_v3/types/uptime.py b/google/cloud/monitoring_v3/types/uptime.py index 69ccc777..f77dd2b8 100644 --- a/google/cloud/monitoring_v3/types/uptime.py +++ b/google/cloud/monitoring_v3/types/uptime.py @@ -412,7 +412,7 @@ class ContentMatcherOption(proto.Enum): is_internal = proto.Field(proto.BOOL, number=15) internal_checkers = proto.RepeatedField( - proto.MESSAGE, number=14, message=InternalChecker, + proto.MESSAGE, number=14, message="InternalChecker", ) diff --git a/noxfile.py b/noxfile.py index a1f04317..41eeb037 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,16 +72,17 @@ 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. session.run( "py.test", "--quiet", - "--cov=google.cloud.monitoring", - "--cov=google.cloud", - "--cov=tests.unit", + "--cov=google/cloud", + "--cov=tests/unit", "--cov-append", "--cov-config=.coveragerc", "--cov-report=", diff --git a/samples/snippets/v3/alerts-client/noxfile.py b/samples/snippets/v3/alerts-client/noxfile.py index ba55d7ce..bca0522e 100644 --- a/samples/snippets/v3/alerts-client/noxfile.py +++ b/samples/snippets/v3/alerts-client/noxfile.py @@ -17,6 +17,7 @@ import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -39,6 +40,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string @@ -64,7 +69,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -93,7 +98,7 @@ def get_pytest_env_vars(): # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -131,8 +136,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +149,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session: nox.sessions.Session) -> None: + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -151,7 +169,7 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -177,7 +195,7 @@ def _session_tests(session, post_install=None): @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -192,7 +210,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -201,6 +219,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -210,7 +233,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) diff --git a/samples/snippets/v3/cloud-client/noxfile.py b/samples/snippets/v3/cloud-client/noxfile.py index ba55d7ce..bca0522e 100644 --- a/samples/snippets/v3/cloud-client/noxfile.py +++ b/samples/snippets/v3/cloud-client/noxfile.py @@ -17,6 +17,7 @@ import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -39,6 +40,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string @@ -64,7 +69,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -93,7 +98,7 @@ def get_pytest_env_vars(): # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -131,8 +136,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +149,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session: nox.sessions.Session) -> None: + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -151,7 +169,7 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -177,7 +195,7 @@ def _session_tests(session, post_install=None): @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -192,7 +210,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -201,6 +219,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -210,7 +233,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) diff --git a/samples/snippets/v3/uptime-check-client/noxfile.py b/samples/snippets/v3/uptime-check-client/noxfile.py index ba55d7ce..bca0522e 100644 --- a/samples/snippets/v3/uptime-check-client/noxfile.py +++ b/samples/snippets/v3/uptime-check-client/noxfile.py @@ -17,6 +17,7 @@ import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -39,6 +40,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string @@ -64,7 +69,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -93,7 +98,7 @@ def get_pytest_env_vars(): # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -131,8 +136,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +149,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session: nox.sessions.Session) -> None: + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -151,7 +169,7 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -177,7 +195,7 @@ def _session_tests(session, post_install=None): @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -192,7 +210,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -201,6 +219,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -210,7 +233,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) diff --git a/scripts/fixup_monitoring_v3_keywords.py b/scripts/fixup_monitoring_v3_keywords.py index b07ce8b3..5527d130 100644 --- a/scripts/fixup_monitoring_v3_keywords.py +++ b/scripts/fixup_monitoring_v3_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/synth.metadata b/synth.metadata index 3b6b973b..3e89b97f 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,22 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-monitoring.git", - "sha": "605ffe066f3154239405e729b7cbfb7ecd69917f" + "remote": "git@github.com:googleapis/python-monitoring", + "sha": "38657f4d47718a1cf52b45068929675249f23f47" + } + }, + { + "git": { + "name": "googleapis", + "remote": "https://github.com/googleapis/googleapis.git", + "sha": "69697504d9eba1d064820c3085b4750767be6d08", + "internalRef": "348952930" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0c868d49b8e05bc1f299bc773df9eb4ef9ed96e9" + "sha": "6133907dbb3ddab204a17a15d5c53ec0aae9b033" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0c868d49b8e05bc1f299bc773df9eb4ef9ed96e9" + "sha": "6133907dbb3ddab204a17a15d5c53ec0aae9b033" } } ], diff --git a/synth.py b/synth.py index cb722a3a..5486781a 100644 --- a/synth.py +++ b/synth.py @@ -13,6 +13,7 @@ # limitations under the License. """This script is used to synthesize generated parts of this library.""" +import re import synthtool as s import synthtool.gcp as gcp @@ -62,6 +63,30 @@ "type" ) +# Comment out broken path helper 'metric_descriptor_path' +# https://github.com/googleapis/gapic-generator-python/issues/701 +s.replace( + "google/cloud/**/metric_service/client.py", + "(@staticmethod\n\s+def metric_descriptor_path.*?return m\.groupdict\(\) if m else \{\})", + """'''\g<1>'''""", + re.MULTILINE| re.DOTALL +) + +s.replace( + "google/cloud/**/metric_service/async_client.py", + """(metric_descriptor_path =.*? + parse_metric_descriptor_path = staticmethod\(.*?\))""", + '''"""\g<1>"""''', + re.MULTILINE| re.DOTALL +) + +s.replace( + "tests/**/test_metric_service.py", + "(def test_metric_descriptor_path.*?def test_parse_metric_descriptor_path.*?)def", + '''"""\g<1>"""\ndef''', + re.MULTILINE| re.DOTALL +) + # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- diff --git a/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py b/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py index 8d5d0df3..1011908a 100644 --- a/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py +++ b/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py @@ -44,7 +44,6 @@ from google.cloud.monitoring_v3.types import alert_service from google.cloud.monitoring_v3.types import common from google.cloud.monitoring_v3.types import mutation_record -from google.cloud.monitoring_v3.types import mutation_record as gm_mutation_record from google.oauth2 import service_account from google.protobuf import any_pb2 as gp_any # type: ignore from google.protobuf import duration_pb2 as duration # type: ignore @@ -109,12 +108,12 @@ def test_alert_policy_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 == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_alert_policy_service_client_get_transport_class(): @@ -475,7 +474,7 @@ def test_list_alert_policies( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert_service.ListAlertPoliciesResponse( @@ -491,6 +490,7 @@ def test_list_alert_policies( assert args[0] == alert_service.ListAlertPoliciesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAlertPoliciesPager) assert response.next_page_token == "next_page_token_value" @@ -501,18 +501,20 @@ def test_list_alert_policies_from_dict(): @pytest.mark.asyncio -async def test_list_alert_policies_async(transport: str = "grpc_asyncio"): +async def test_list_alert_policies_async( + transport: str = "grpc_asyncio", request_type=alert_service.ListAlertPoliciesRequest +): client = AlertPolicyServiceAsyncClient( 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 = alert_service.ListAlertPoliciesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -527,7 +529,7 @@ async def test_list_alert_policies_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == alert_service.ListAlertPoliciesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAlertPoliciesAsyncPager) @@ -535,6 +537,11 @@ async def test_list_alert_policies_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_alert_policies_async_from_dict(): + await test_list_alert_policies_async(request_type=dict) + + def test_list_alert_policies_field_headers(): client = AlertPolicyServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -545,7 +552,7 @@ def test_list_alert_policies_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: call.return_value = alert_service.ListAlertPoliciesResponse() @@ -574,7 +581,7 @@ async def test_list_alert_policies_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( alert_service.ListAlertPoliciesResponse() @@ -597,7 +604,7 @@ def test_list_alert_policies_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert_service.ListAlertPoliciesResponse() @@ -633,7 +640,7 @@ async def test_list_alert_policies_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert_service.ListAlertPoliciesResponse() @@ -672,7 +679,7 @@ def test_list_alert_policies_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -714,7 +721,7 @@ def test_list_alert_policies_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_alert_policies), "__call__" + type(client.transport.list_alert_policies), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -750,7 +757,7 @@ async def test_list_alert_policies_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_alert_policies), + type(client.transport.list_alert_policies), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -793,7 +800,7 @@ async def test_list_alert_policies_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_alert_policies), + type(client.transport.list_alert_policies), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -837,9 +844,7 @@ def test_get_alert_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.get_alert_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_alert_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy( name="name_value", @@ -857,6 +862,7 @@ def test_get_alert_policy( assert args[0] == alert_service.GetAlertPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, alert.AlertPolicy) assert response.name == "name_value" @@ -873,19 +879,19 @@ def test_get_alert_policy_from_dict(): @pytest.mark.asyncio -async def test_get_alert_policy_async(transport: str = "grpc_asyncio"): +async def test_get_alert_policy_async( + transport: str = "grpc_asyncio", request_type=alert_service.GetAlertPolicyRequest +): client = AlertPolicyServiceAsyncClient( 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 = alert_service.GetAlertPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_alert_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_alert_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( alert.AlertPolicy( @@ -902,7 +908,7 @@ async def test_get_alert_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == alert_service.GetAlertPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, alert.AlertPolicy) @@ -916,6 +922,11 @@ async def test_get_alert_policy_async(transport: str = "grpc_asyncio"): assert response.notification_channels == ["notification_channels_value"] +@pytest.mark.asyncio +async def test_get_alert_policy_async_from_dict(): + await test_get_alert_policy_async(request_type=dict) + + def test_get_alert_policy_field_headers(): client = AlertPolicyServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -925,9 +936,7 @@ def test_get_alert_policy_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_alert_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_alert_policy), "__call__") as call: call.return_value = alert.AlertPolicy() client.get_alert_policy(request) @@ -954,9 +963,7 @@ async def test_get_alert_policy_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_alert_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_alert_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(alert.AlertPolicy()) await client.get_alert_policy(request) @@ -975,9 +982,7 @@ def test_get_alert_policy_flattened(): client = AlertPolicyServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.get_alert_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_alert_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy() @@ -1011,9 +1016,7 @@ async def test_get_alert_policy_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_alert_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_alert_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy() @@ -1057,7 +1060,7 @@ def test_create_alert_policy( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_alert_policy), "__call__" + type(client.transport.create_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy( @@ -1076,6 +1079,7 @@ def test_create_alert_policy( assert args[0] == alert_service.CreateAlertPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, alert.AlertPolicy) assert response.name == "name_value" @@ -1092,18 +1096,20 @@ def test_create_alert_policy_from_dict(): @pytest.mark.asyncio -async def test_create_alert_policy_async(transport: str = "grpc_asyncio"): +async def test_create_alert_policy_async( + transport: str = "grpc_asyncio", request_type=alert_service.CreateAlertPolicyRequest +): client = AlertPolicyServiceAsyncClient( 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 = alert_service.CreateAlertPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_alert_policy), "__call__" + type(client.transport.create_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1121,7 +1127,7 @@ async def test_create_alert_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == alert_service.CreateAlertPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, alert.AlertPolicy) @@ -1135,6 +1141,11 @@ async def test_create_alert_policy_async(transport: str = "grpc_asyncio"): assert response.notification_channels == ["notification_channels_value"] +@pytest.mark.asyncio +async def test_create_alert_policy_async_from_dict(): + await test_create_alert_policy_async(request_type=dict) + + def test_create_alert_policy_field_headers(): client = AlertPolicyServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1145,7 +1156,7 @@ def test_create_alert_policy_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_alert_policy), "__call__" + type(client.transport.create_alert_policy), "__call__" ) as call: call.return_value = alert.AlertPolicy() @@ -1174,7 +1185,7 @@ async def test_create_alert_policy_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_alert_policy), "__call__" + type(client.transport.create_alert_policy), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(alert.AlertPolicy()) @@ -1195,7 +1206,7 @@ def test_create_alert_policy_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_alert_policy), "__call__" + type(client.transport.create_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy() @@ -1237,7 +1248,7 @@ async def test_create_alert_policy_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_alert_policy), "__call__" + type(client.transport.create_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy() @@ -1288,7 +1299,7 @@ def test_delete_alert_policy( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_alert_policy), "__call__" + type(client.transport.delete_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1310,18 +1321,20 @@ def test_delete_alert_policy_from_dict(): @pytest.mark.asyncio -async def test_delete_alert_policy_async(transport: str = "grpc_asyncio"): +async def test_delete_alert_policy_async( + transport: str = "grpc_asyncio", request_type=alert_service.DeleteAlertPolicyRequest +): client = AlertPolicyServiceAsyncClient( 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 = alert_service.DeleteAlertPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_alert_policy), "__call__" + type(client.transport.delete_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1332,12 +1345,17 @@ async def test_delete_alert_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == alert_service.DeleteAlertPolicyRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_alert_policy_async_from_dict(): + await test_delete_alert_policy_async(request_type=dict) + + def test_delete_alert_policy_field_headers(): client = AlertPolicyServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1348,7 +1366,7 @@ def test_delete_alert_policy_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_alert_policy), "__call__" + type(client.transport.delete_alert_policy), "__call__" ) as call: call.return_value = None @@ -1377,7 +1395,7 @@ async def test_delete_alert_policy_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_alert_policy), "__call__" + type(client.transport.delete_alert_policy), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1398,7 +1416,7 @@ def test_delete_alert_policy_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_alert_policy), "__call__" + type(client.transport.delete_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1434,7 +1452,7 @@ async def test_delete_alert_policy_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_alert_policy), "__call__" + type(client.transport.delete_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1479,7 +1497,7 @@ def test_update_alert_policy( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_alert_policy), "__call__" + type(client.transport.update_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy( @@ -1498,6 +1516,7 @@ def test_update_alert_policy( assert args[0] == alert_service.UpdateAlertPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, alert.AlertPolicy) assert response.name == "name_value" @@ -1514,18 +1533,20 @@ def test_update_alert_policy_from_dict(): @pytest.mark.asyncio -async def test_update_alert_policy_async(transport: str = "grpc_asyncio"): +async def test_update_alert_policy_async( + transport: str = "grpc_asyncio", request_type=alert_service.UpdateAlertPolicyRequest +): client = AlertPolicyServiceAsyncClient( 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 = alert_service.UpdateAlertPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_alert_policy), "__call__" + type(client.transport.update_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1543,7 +1564,7 @@ async def test_update_alert_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == alert_service.UpdateAlertPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, alert.AlertPolicy) @@ -1557,6 +1578,11 @@ async def test_update_alert_policy_async(transport: str = "grpc_asyncio"): assert response.notification_channels == ["notification_channels_value"] +@pytest.mark.asyncio +async def test_update_alert_policy_async_from_dict(): + await test_update_alert_policy_async(request_type=dict) + + def test_update_alert_policy_field_headers(): client = AlertPolicyServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1567,7 +1593,7 @@ def test_update_alert_policy_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_alert_policy), "__call__" + type(client.transport.update_alert_policy), "__call__" ) as call: call.return_value = alert.AlertPolicy() @@ -1599,7 +1625,7 @@ async def test_update_alert_policy_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_alert_policy), "__call__" + type(client.transport.update_alert_policy), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(alert.AlertPolicy()) @@ -1623,7 +1649,7 @@ def test_update_alert_policy_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_alert_policy), "__call__" + type(client.transport.update_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy() @@ -1666,7 +1692,7 @@ async def test_update_alert_policy_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_alert_policy), "__call__" + type(client.transport.update_alert_policy), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = alert.AlertPolicy() @@ -1741,7 +1767,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = AlertPolicyServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -1777,7 +1803,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AlertPolicyServiceClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.AlertPolicyServiceGrpcTransport,) + assert isinstance(client.transport, transports.AlertPolicyServiceGrpcTransport,) def test_alert_policy_service_base_transport_error(): @@ -1887,7 +1913,7 @@ def test_alert_policy_service_host_no_port(): api_endpoint="monitoring.googleapis.com" ), ) - assert client._transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_alert_policy_service_host_with_port(): @@ -1897,7 +1923,7 @@ def test_alert_policy_service_host_with_port(): api_endpoint="monitoring.googleapis.com:8000" ), ) - assert client._transport._host == "monitoring.googleapis.com:8000" + assert client.transport._host == "monitoring.googleapis.com:8000" def test_alert_policy_service_grpc_transport_channel(): @@ -1909,6 +1935,7 @@ def test_alert_policy_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_alert_policy_service_grpc_asyncio_transport_channel(): @@ -1920,6 +1947,7 @@ def test_alert_policy_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( @@ -1969,8 +1997,13 @@ def test_alert_policy_service_transport_channel_mtls_with_client_cert_source( ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2013,6 +2046,10 @@ def test_alert_policy_service_transport_channel_mtls_with_adc(transport_class): ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel @@ -2067,81 +2104,81 @@ def test_parse_alert_policy_condition_path(): assert expected == actual -def test_common_project_path(): - project = "scallop" +def test_common_billing_account_path(): + billing_account = "scallop" - expected = "projects/{project}".format(project=project,) - actual = AlertPolicyServiceClient.common_project_path(project) + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = AlertPolicyServiceClient.common_billing_account_path(billing_account) assert expected == actual -def test_parse_common_project_path(): +def test_parse_common_billing_account_path(): expected = { - "project": "abalone", + "billing_account": "abalone", } - path = AlertPolicyServiceClient.common_project_path(**expected) + path = AlertPolicyServiceClient.common_billing_account_path(**expected) # Check that the path construction is reversible. - actual = AlertPolicyServiceClient.parse_common_project_path(path) + actual = AlertPolicyServiceClient.parse_common_billing_account_path(path) assert expected == actual -def test_common_organization_path(): - organization = "squid" +def test_common_folder_path(): + folder = "squid" - expected = "organizations/{organization}".format(organization=organization,) - actual = AlertPolicyServiceClient.common_organization_path(organization) + expected = "folders/{folder}".format(folder=folder,) + actual = AlertPolicyServiceClient.common_folder_path(folder) assert expected == actual -def test_parse_common_organization_path(): +def test_parse_common_folder_path(): expected = { - "organization": "clam", + "folder": "clam", } - path = AlertPolicyServiceClient.common_organization_path(**expected) + path = AlertPolicyServiceClient.common_folder_path(**expected) # Check that the path construction is reversible. - actual = AlertPolicyServiceClient.parse_common_organization_path(path) + actual = AlertPolicyServiceClient.parse_common_folder_path(path) assert expected == actual -def test_common_folder_path(): - folder = "whelk" +def test_common_organization_path(): + organization = "whelk" - expected = "folders/{folder}".format(folder=folder,) - actual = AlertPolicyServiceClient.common_folder_path(folder) + expected = "organizations/{organization}".format(organization=organization,) + actual = AlertPolicyServiceClient.common_organization_path(organization) assert expected == actual -def test_parse_common_folder_path(): +def test_parse_common_organization_path(): expected = { - "folder": "octopus", + "organization": "octopus", } - path = AlertPolicyServiceClient.common_folder_path(**expected) + path = AlertPolicyServiceClient.common_organization_path(**expected) # Check that the path construction is reversible. - actual = AlertPolicyServiceClient.parse_common_folder_path(path) + actual = AlertPolicyServiceClient.parse_common_organization_path(path) assert expected == actual -def test_common_billing_account_path(): - billing_account = "oyster" +def test_common_project_path(): + project = "oyster" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = AlertPolicyServiceClient.common_billing_account_path(billing_account) + expected = "projects/{project}".format(project=project,) + actual = AlertPolicyServiceClient.common_project_path(project) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_common_project_path(): expected = { - "billing_account": "nudibranch", + "project": "nudibranch", } - path = AlertPolicyServiceClient.common_billing_account_path(**expected) + path = AlertPolicyServiceClient.common_project_path(**expected) # Check that the path construction is reversible. - actual = AlertPolicyServiceClient.parse_common_billing_account_path(path) + actual = AlertPolicyServiceClient.parse_common_project_path(path) assert expected == actual diff --git a/tests/unit/gapic/monitoring_v3/test_group_service.py b/tests/unit/gapic/monitoring_v3/test_group_service.py index df85d219..8efea06a 100644 --- a/tests/unit/gapic/monitoring_v3/test_group_service.py +++ b/tests/unit/gapic/monitoring_v3/test_group_service.py @@ -94,12 +94,12 @@ def test_group_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 == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_group_service_client_get_transport_class(): @@ -443,7 +443,7 @@ def test_list_groups( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_groups), "__call__") as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = group_service.ListGroupsResponse( next_page_token="next_page_token_value", @@ -458,6 +458,7 @@ def test_list_groups( assert args[0] == group_service.ListGroupsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListGroupsPager) assert response.next_page_token == "next_page_token_value" @@ -468,19 +469,19 @@ def test_list_groups_from_dict(): @pytest.mark.asyncio -async def test_list_groups_async(transport: str = "grpc_asyncio"): +async def test_list_groups_async( + transport: str = "grpc_asyncio", request_type=group_service.ListGroupsRequest +): client = GroupServiceAsyncClient( 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 = group_service.ListGroupsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_groups), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( group_service.ListGroupsResponse(next_page_token="next_page_token_value",) @@ -492,7 +493,7 @@ async def test_list_groups_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == group_service.ListGroupsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListGroupsAsyncPager) @@ -500,6 +501,11 @@ async def test_list_groups_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_groups_async_from_dict(): + await test_list_groups_async(request_type=dict) + + def test_list_groups_field_headers(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -509,7 +515,7 @@ def test_list_groups_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.list_groups), "__call__") as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: call.return_value = group_service.ListGroupsResponse() client.list_groups(request) @@ -534,9 +540,7 @@ async def test_list_groups_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.list_groups), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( group_service.ListGroupsResponse() ) @@ -557,7 +561,7 @@ def test_list_groups_flattened(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_groups), "__call__") as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = group_service.ListGroupsResponse() @@ -589,9 +593,7 @@ async def test_list_groups_flattened_async(): client = GroupServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_groups), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = group_service.ListGroupsResponse() @@ -626,7 +628,7 @@ def test_list_groups_pager(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_groups), "__call__") as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( group_service.ListGroupsResponse( @@ -658,7 +660,7 @@ def test_list_groups_pages(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_groups), "__call__") as call: + with mock.patch.object(type(client.transport.list_groups), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( group_service.ListGroupsResponse( @@ -683,9 +685,7 @@ async def test_list_groups_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_groups), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_groups), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -716,9 +716,7 @@ async def test_list_groups_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_groups), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_groups), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -750,7 +748,7 @@ def test_get_group(transport: str = "grpc", request_type=group_service.GetGroupR request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_group), "__call__") as call: + with mock.patch.object(type(client.transport.get_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = group.Group( name="name_value", @@ -769,6 +767,7 @@ def test_get_group(transport: str = "grpc", request_type=group_service.GetGroupR assert args[0] == group_service.GetGroupRequest() # Establish that the response is the type that we expect. + assert isinstance(response, group.Group) assert response.name == "name_value" @@ -787,19 +786,19 @@ def test_get_group_from_dict(): @pytest.mark.asyncio -async def test_get_group_async(transport: str = "grpc_asyncio"): +async def test_get_group_async( + transport: str = "grpc_asyncio", request_type=group_service.GetGroupRequest +): client = GroupServiceAsyncClient( 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 = group_service.GetGroupRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( group.Group( @@ -817,7 +816,7 @@ async def test_get_group_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == group_service.GetGroupRequest() # Establish that the response is the type that we expect. assert isinstance(response, group.Group) @@ -833,6 +832,11 @@ async def test_get_group_async(transport: str = "grpc_asyncio"): assert response.is_cluster is True +@pytest.mark.asyncio +async def test_get_group_async_from_dict(): + await test_get_group_async(request_type=dict) + + def test_get_group_field_headers(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -842,7 +846,7 @@ def test_get_group_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_group), "__call__") as call: + with mock.patch.object(type(client.transport.get_group), "__call__") as call: call.return_value = group.Group() client.get_group(request) @@ -867,9 +871,7 @@ async def test_get_group_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_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_group), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(group.Group()) await client.get_group(request) @@ -888,7 +890,7 @@ def test_get_group_flattened(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_group), "__call__") as call: + with mock.patch.object(type(client.transport.get_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = group.Group() @@ -920,9 +922,7 @@ async def test_get_group_flattened_async(): client = GroupServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = group.Group() @@ -963,7 +963,7 @@ def test_create_group( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_group), "__call__") as call: + with mock.patch.object(type(client.transport.create_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_group.Group( name="name_value", @@ -982,6 +982,7 @@ def test_create_group( assert args[0] == group_service.CreateGroupRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gm_group.Group) assert response.name == "name_value" @@ -1000,19 +1001,19 @@ def test_create_group_from_dict(): @pytest.mark.asyncio -async def test_create_group_async(transport: str = "grpc_asyncio"): +async def test_create_group_async( + transport: str = "grpc_asyncio", request_type=group_service.CreateGroupRequest +): client = GroupServiceAsyncClient( 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 = group_service.CreateGroupRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gm_group.Group( @@ -1030,7 +1031,7 @@ async def test_create_group_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == group_service.CreateGroupRequest() # Establish that the response is the type that we expect. assert isinstance(response, gm_group.Group) @@ -1046,6 +1047,11 @@ async def test_create_group_async(transport: str = "grpc_asyncio"): assert response.is_cluster is True +@pytest.mark.asyncio +async def test_create_group_async_from_dict(): + await test_create_group_async(request_type=dict) + + def test_create_group_field_headers(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1055,7 +1061,7 @@ def test_create_group_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.create_group), "__call__") as call: + with mock.patch.object(type(client.transport.create_group), "__call__") as call: call.return_value = gm_group.Group() client.create_group(request) @@ -1080,9 +1086,7 @@ async def test_create_group_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.create_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_group), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gm_group.Group()) await client.create_group(request) @@ -1101,7 +1105,7 @@ def test_create_group_flattened(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_group), "__call__") as call: + with mock.patch.object(type(client.transport.create_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_group.Group() @@ -1139,9 +1143,7 @@ async def test_create_group_flattened_async(): client = GroupServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_group.Group() @@ -1188,7 +1190,7 @@ def test_update_group( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_group), "__call__") as call: + with mock.patch.object(type(client.transport.update_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_group.Group( name="name_value", @@ -1207,6 +1209,7 @@ def test_update_group( assert args[0] == group_service.UpdateGroupRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gm_group.Group) assert response.name == "name_value" @@ -1225,19 +1228,19 @@ def test_update_group_from_dict(): @pytest.mark.asyncio -async def test_update_group_async(transport: str = "grpc_asyncio"): +async def test_update_group_async( + transport: str = "grpc_asyncio", request_type=group_service.UpdateGroupRequest +): client = GroupServiceAsyncClient( 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 = group_service.UpdateGroupRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gm_group.Group( @@ -1255,7 +1258,7 @@ async def test_update_group_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == group_service.UpdateGroupRequest() # Establish that the response is the type that we expect. assert isinstance(response, gm_group.Group) @@ -1271,6 +1274,11 @@ async def test_update_group_async(transport: str = "grpc_asyncio"): assert response.is_cluster is True +@pytest.mark.asyncio +async def test_update_group_async_from_dict(): + await test_update_group_async(request_type=dict) + + def test_update_group_field_headers(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1280,7 +1288,7 @@ def test_update_group_field_headers(): request.group.name = "group.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_group), "__call__") as call: + with mock.patch.object(type(client.transport.update_group), "__call__") as call: call.return_value = gm_group.Group() client.update_group(request) @@ -1305,9 +1313,7 @@ async def test_update_group_field_headers_async(): request.group.name = "group.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_group), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gm_group.Group()) await client.update_group(request) @@ -1326,7 +1332,7 @@ def test_update_group_flattened(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_group), "__call__") as call: + with mock.patch.object(type(client.transport.update_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_group.Group() @@ -1358,9 +1364,7 @@ async def test_update_group_flattened_async(): client = GroupServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_group.Group() @@ -1401,7 +1405,7 @@ def test_delete_group( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_group), "__call__") as call: + with mock.patch.object(type(client.transport.delete_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1422,19 +1426,19 @@ def test_delete_group_from_dict(): @pytest.mark.asyncio -async def test_delete_group_async(transport: str = "grpc_asyncio"): +async def test_delete_group_async( + transport: str = "grpc_asyncio", request_type=group_service.DeleteGroupRequest +): client = GroupServiceAsyncClient( 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 = group_service.DeleteGroupRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1444,12 +1448,17 @@ async def test_delete_group_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == group_service.DeleteGroupRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_group_async_from_dict(): + await test_delete_group_async(request_type=dict) + + def test_delete_group_field_headers(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1459,7 +1468,7 @@ def test_delete_group_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_group), "__call__") as call: + with mock.patch.object(type(client.transport.delete_group), "__call__") as call: call.return_value = None client.delete_group(request) @@ -1484,9 +1493,7 @@ async def test_delete_group_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_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_group), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_group(request) @@ -1505,7 +1512,7 @@ def test_delete_group_flattened(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_group), "__call__") as call: + with mock.patch.object(type(client.transport.delete_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1537,9 +1544,7 @@ async def test_delete_group_flattened_async(): client = GroupServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_group), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_group), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1581,7 +1586,7 @@ def test_list_group_members( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = group_service.ListGroupMembersResponse( @@ -1597,6 +1602,7 @@ def test_list_group_members( assert args[0] == group_service.ListGroupMembersRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListGroupMembersPager) assert response.next_page_token == "next_page_token_value" @@ -1609,18 +1615,20 @@ def test_list_group_members_from_dict(): @pytest.mark.asyncio -async def test_list_group_members_async(transport: str = "grpc_asyncio"): +async def test_list_group_members_async( + transport: str = "grpc_asyncio", request_type=group_service.ListGroupMembersRequest +): client = GroupServiceAsyncClient( 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 = group_service.ListGroupMembersRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1635,7 +1643,7 @@ async def test_list_group_members_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == group_service.ListGroupMembersRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListGroupMembersAsyncPager) @@ -1645,6 +1653,11 @@ async def test_list_group_members_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_group_members_async_from_dict(): + await test_list_group_members_async(request_type=dict) + + def test_list_group_members_field_headers(): client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1655,7 +1668,7 @@ def test_list_group_members_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: call.return_value = group_service.ListGroupMembersResponse() @@ -1682,7 +1695,7 @@ async def test_list_group_members_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( group_service.ListGroupMembersResponse() @@ -1705,7 +1718,7 @@ def test_list_group_members_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = group_service.ListGroupMembersResponse() @@ -1739,7 +1752,7 @@ async def test_list_group_members_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = group_service.ListGroupMembersResponse() @@ -1776,7 +1789,7 @@ def test_list_group_members_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1820,7 +1833,7 @@ def test_list_group_members_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_group_members), "__call__" + type(client.transport.list_group_members), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1856,7 +1869,7 @@ async def test_list_group_members_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_group_members), + type(client.transport.list_group_members), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1901,7 +1914,7 @@ async def test_list_group_members_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_group_members), + type(client.transport.list_group_members), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1971,7 +1984,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = GroupServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2004,7 +2017,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = GroupServiceClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.GroupServiceGrpcTransport,) + assert isinstance(client.transport, transports.GroupServiceGrpcTransport,) def test_group_service_base_transport_error(): @@ -2115,7 +2128,7 @@ def test_group_service_host_no_port(): api_endpoint="monitoring.googleapis.com" ), ) - assert client._transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_group_service_host_with_port(): @@ -2125,7 +2138,7 @@ def test_group_service_host_with_port(): api_endpoint="monitoring.googleapis.com:8000" ), ) - assert client._transport._host == "monitoring.googleapis.com:8000" + assert client.transport._host == "monitoring.googleapis.com:8000" def test_group_service_grpc_transport_channel(): @@ -2137,6 +2150,7 @@ def test_group_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_group_service_grpc_asyncio_transport_channel(): @@ -2148,6 +2162,7 @@ def test_group_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( @@ -2192,8 +2207,13 @@ def test_group_service_transport_channel_mtls_with_client_cert_source(transport_ ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2233,6 +2253,10 @@ def test_group_service_transport_channel_mtls_with_adc(transport_class): ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel @@ -2258,81 +2282,81 @@ def test_parse_group_path(): assert expected == actual -def test_common_project_path(): - project = "oyster" +def test_common_billing_account_path(): + billing_account = "oyster" - expected = "projects/{project}".format(project=project,) - actual = GroupServiceClient.common_project_path(project) + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = GroupServiceClient.common_billing_account_path(billing_account) assert expected == actual -def test_parse_common_project_path(): +def test_parse_common_billing_account_path(): expected = { - "project": "nudibranch", + "billing_account": "nudibranch", } - path = GroupServiceClient.common_project_path(**expected) + path = GroupServiceClient.common_billing_account_path(**expected) # Check that the path construction is reversible. - actual = GroupServiceClient.parse_common_project_path(path) + actual = GroupServiceClient.parse_common_billing_account_path(path) assert expected == actual -def test_common_organization_path(): - organization = "cuttlefish" +def test_common_folder_path(): + folder = "cuttlefish" - expected = "organizations/{organization}".format(organization=organization,) - actual = GroupServiceClient.common_organization_path(organization) + expected = "folders/{folder}".format(folder=folder,) + actual = GroupServiceClient.common_folder_path(folder) assert expected == actual -def test_parse_common_organization_path(): +def test_parse_common_folder_path(): expected = { - "organization": "mussel", + "folder": "mussel", } - path = GroupServiceClient.common_organization_path(**expected) + path = GroupServiceClient.common_folder_path(**expected) # Check that the path construction is reversible. - actual = GroupServiceClient.parse_common_organization_path(path) + actual = GroupServiceClient.parse_common_folder_path(path) assert expected == actual -def test_common_folder_path(): - folder = "winkle" +def test_common_organization_path(): + organization = "winkle" - expected = "folders/{folder}".format(folder=folder,) - actual = GroupServiceClient.common_folder_path(folder) + expected = "organizations/{organization}".format(organization=organization,) + actual = GroupServiceClient.common_organization_path(organization) assert expected == actual -def test_parse_common_folder_path(): +def test_parse_common_organization_path(): expected = { - "folder": "nautilus", + "organization": "nautilus", } - path = GroupServiceClient.common_folder_path(**expected) + path = GroupServiceClient.common_organization_path(**expected) # Check that the path construction is reversible. - actual = GroupServiceClient.parse_common_folder_path(path) + actual = GroupServiceClient.parse_common_organization_path(path) assert expected == actual -def test_common_billing_account_path(): - billing_account = "scallop" +def test_common_project_path(): + project = "scallop" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = GroupServiceClient.common_billing_account_path(billing_account) + expected = "projects/{project}".format(project=project,) + actual = GroupServiceClient.common_project_path(project) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_common_project_path(): expected = { - "billing_account": "abalone", + "project": "abalone", } - path = GroupServiceClient.common_billing_account_path(**expected) + path = GroupServiceClient.common_project_path(**expected) # Check that the path construction is reversible. - actual = GroupServiceClient.parse_common_billing_account_path(path) + actual = GroupServiceClient.parse_common_project_path(path) assert expected == actual diff --git a/tests/unit/gapic/monitoring_v3/test_metric_service.py b/tests/unit/gapic/monitoring_v3/test_metric_service.py index 7980a123..a88ac1af 100644 --- a/tests/unit/gapic/monitoring_v3/test_metric_service.py +++ b/tests/unit/gapic/monitoring_v3/test_metric_service.py @@ -29,7 +29,6 @@ from google.api import label_pb2 as label # type: ignore from google.api import launch_stage_pb2 as launch_stage # type: ignore from google.api import metric_pb2 as ga_metric # type: ignore -from google.api import metric_pb2 as metric # type: ignore from google.api import monitored_resource_pb2 as monitored_resource # type: ignore from google.api_core import client_options from google.api_core import exceptions @@ -106,12 +105,12 @@ def test_metric_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 == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_metric_service_client_get_transport_class(): @@ -463,7 +462,7 @@ def test_list_monitored_resource_descriptors( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListMonitoredResourceDescriptorsResponse( @@ -479,6 +478,7 @@ def test_list_monitored_resource_descriptors( assert args[0] == metric_service.ListMonitoredResourceDescriptorsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMonitoredResourceDescriptorsPager) assert response.next_page_token == "next_page_token_value" @@ -491,6 +491,7 @@ def test_list_monitored_resource_descriptors_from_dict(): @pytest.mark.asyncio async def test_list_monitored_resource_descriptors_async( transport: str = "grpc_asyncio", + request_type=metric_service.ListMonitoredResourceDescriptorsRequest, ): client = MetricServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -498,11 +499,11 @@ async def test_list_monitored_resource_descriptors_async( # 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 = metric_service.ListMonitoredResourceDescriptorsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -517,7 +518,7 @@ async def test_list_monitored_resource_descriptors_async( assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.ListMonitoredResourceDescriptorsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListMonitoredResourceDescriptorsAsyncPager) @@ -525,6 +526,11 @@ async def test_list_monitored_resource_descriptors_async( assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_monitored_resource_descriptors_async_from_dict(): + await test_list_monitored_resource_descriptors_async(request_type=dict) + + def test_list_monitored_resource_descriptors_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -535,7 +541,7 @@ def test_list_monitored_resource_descriptors_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: call.return_value = metric_service.ListMonitoredResourceDescriptorsResponse() @@ -562,7 +568,7 @@ async def test_list_monitored_resource_descriptors_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( metric_service.ListMonitoredResourceDescriptorsResponse() @@ -585,7 +591,7 @@ def test_list_monitored_resource_descriptors_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListMonitoredResourceDescriptorsResponse() @@ -619,7 +625,7 @@ async def test_list_monitored_resource_descriptors_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListMonitoredResourceDescriptorsResponse() @@ -656,7 +662,7 @@ def test_list_monitored_resource_descriptors_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -707,7 +713,7 @@ def test_list_monitored_resource_descriptors_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_monitored_resource_descriptors), "__call__" + type(client.transport.list_monitored_resource_descriptors), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -747,7 +753,7 @@ async def test_list_monitored_resource_descriptors_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_monitored_resource_descriptors), + type(client.transport.list_monitored_resource_descriptors), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -797,7 +803,7 @@ async def test_list_monitored_resource_descriptors_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_monitored_resource_descriptors), + type(client.transport.list_monitored_resource_descriptors), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -851,7 +857,7 @@ def test_get_monitored_resource_descriptor( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_monitored_resource_descriptor), "__call__" + type(client.transport.get_monitored_resource_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = monitored_resource.MonitoredResourceDescriptor( @@ -870,6 +876,7 @@ def test_get_monitored_resource_descriptor( assert args[0] == metric_service.GetMonitoredResourceDescriptorRequest() # Establish that the response is the type that we expect. + assert isinstance(response, monitored_resource.MonitoredResourceDescriptor) assert response.name == "name_value" @@ -886,18 +893,21 @@ def test_get_monitored_resource_descriptor_from_dict(): @pytest.mark.asyncio -async def test_get_monitored_resource_descriptor_async(transport: str = "grpc_asyncio"): +async def test_get_monitored_resource_descriptor_async( + transport: str = "grpc_asyncio", + request_type=metric_service.GetMonitoredResourceDescriptorRequest, +): client = MetricServiceAsyncClient( 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 = metric_service.GetMonitoredResourceDescriptorRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_monitored_resource_descriptor), "__call__" + type(client.transport.get_monitored_resource_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -915,7 +925,7 @@ async def test_get_monitored_resource_descriptor_async(transport: str = "grpc_as assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.GetMonitoredResourceDescriptorRequest() # Establish that the response is the type that we expect. assert isinstance(response, monitored_resource.MonitoredResourceDescriptor) @@ -929,6 +939,11 @@ async def test_get_monitored_resource_descriptor_async(transport: str = "grpc_as assert response.description == "description_value" +@pytest.mark.asyncio +async def test_get_monitored_resource_descriptor_async_from_dict(): + await test_get_monitored_resource_descriptor_async(request_type=dict) + + def test_get_monitored_resource_descriptor_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -939,7 +954,7 @@ def test_get_monitored_resource_descriptor_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_monitored_resource_descriptor), "__call__" + type(client.transport.get_monitored_resource_descriptor), "__call__" ) as call: call.return_value = monitored_resource.MonitoredResourceDescriptor() @@ -966,7 +981,7 @@ async def test_get_monitored_resource_descriptor_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_monitored_resource_descriptor), "__call__" + type(client.transport.get_monitored_resource_descriptor), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( monitored_resource.MonitoredResourceDescriptor() @@ -989,7 +1004,7 @@ def test_get_monitored_resource_descriptor_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_monitored_resource_descriptor), "__call__" + type(client.transport.get_monitored_resource_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = monitored_resource.MonitoredResourceDescriptor() @@ -1023,7 +1038,7 @@ async def test_get_monitored_resource_descriptor_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_monitored_resource_descriptor), "__call__" + type(client.transport.get_monitored_resource_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = monitored_resource.MonitoredResourceDescriptor() @@ -1068,7 +1083,7 @@ def test_list_metric_descriptors( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListMetricDescriptorsResponse( @@ -1084,6 +1099,7 @@ def test_list_metric_descriptors( assert args[0] == metric_service.ListMetricDescriptorsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMetricDescriptorsPager) assert response.next_page_token == "next_page_token_value" @@ -1094,18 +1110,21 @@ def test_list_metric_descriptors_from_dict(): @pytest.mark.asyncio -async def test_list_metric_descriptors_async(transport: str = "grpc_asyncio"): +async def test_list_metric_descriptors_async( + transport: str = "grpc_asyncio", + request_type=metric_service.ListMetricDescriptorsRequest, +): client = MetricServiceAsyncClient( 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 = metric_service.ListMetricDescriptorsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1120,7 +1139,7 @@ async def test_list_metric_descriptors_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.ListMetricDescriptorsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListMetricDescriptorsAsyncPager) @@ -1128,6 +1147,11 @@ async def test_list_metric_descriptors_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_metric_descriptors_async_from_dict(): + await test_list_metric_descriptors_async(request_type=dict) + + def test_list_metric_descriptors_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1138,7 +1162,7 @@ def test_list_metric_descriptors_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: call.return_value = metric_service.ListMetricDescriptorsResponse() @@ -1165,7 +1189,7 @@ async def test_list_metric_descriptors_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( metric_service.ListMetricDescriptorsResponse() @@ -1188,7 +1212,7 @@ def test_list_metric_descriptors_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListMetricDescriptorsResponse() @@ -1222,7 +1246,7 @@ async def test_list_metric_descriptors_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListMetricDescriptorsResponse() @@ -1259,7 +1283,7 @@ def test_list_metric_descriptors_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1305,7 +1329,7 @@ def test_list_metric_descriptors_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_metric_descriptors), "__call__" + type(client.transport.list_metric_descriptors), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1343,7 +1367,7 @@ async def test_list_metric_descriptors_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_metric_descriptors), + type(client.transport.list_metric_descriptors), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1388,7 +1412,7 @@ async def test_list_metric_descriptors_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_metric_descriptors), + type(client.transport.list_metric_descriptors), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1437,7 +1461,7 @@ def test_get_metric_descriptor( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_metric_descriptor), "__call__" + type(client.transport.get_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ga_metric.MetricDescriptor( @@ -1459,6 +1483,7 @@ def test_get_metric_descriptor( assert args[0] == metric_service.GetMetricDescriptorRequest() # Establish that the response is the type that we expect. + assert isinstance(response, ga_metric.MetricDescriptor) assert response.name == "name_value" @@ -1481,18 +1506,21 @@ def test_get_metric_descriptor_from_dict(): @pytest.mark.asyncio -async def test_get_metric_descriptor_async(transport: str = "grpc_asyncio"): +async def test_get_metric_descriptor_async( + transport: str = "grpc_asyncio", + request_type=metric_service.GetMetricDescriptorRequest, +): client = MetricServiceAsyncClient( 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 = metric_service.GetMetricDescriptorRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_metric_descriptor), "__call__" + type(client.transport.get_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1513,7 +1541,7 @@ async def test_get_metric_descriptor_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.GetMetricDescriptorRequest() # Establish that the response is the type that we expect. assert isinstance(response, ga_metric.MetricDescriptor) @@ -1533,6 +1561,11 @@ async def test_get_metric_descriptor_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_get_metric_descriptor_async_from_dict(): + await test_get_metric_descriptor_async(request_type=dict) + + def test_get_metric_descriptor_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1543,7 +1576,7 @@ def test_get_metric_descriptor_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_metric_descriptor), "__call__" + type(client.transport.get_metric_descriptor), "__call__" ) as call: call.return_value = ga_metric.MetricDescriptor() @@ -1570,7 +1603,7 @@ async def test_get_metric_descriptor_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_metric_descriptor), "__call__" + type(client.transport.get_metric_descriptor), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( ga_metric.MetricDescriptor() @@ -1593,7 +1626,7 @@ def test_get_metric_descriptor_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_metric_descriptor), "__call__" + type(client.transport.get_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ga_metric.MetricDescriptor() @@ -1627,7 +1660,7 @@ async def test_get_metric_descriptor_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_metric_descriptor), "__call__" + type(client.transport.get_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ga_metric.MetricDescriptor() @@ -1672,7 +1705,7 @@ def test_create_metric_descriptor( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_metric_descriptor), "__call__" + type(client.transport.create_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ga_metric.MetricDescriptor( @@ -1694,6 +1727,7 @@ def test_create_metric_descriptor( assert args[0] == metric_service.CreateMetricDescriptorRequest() # Establish that the response is the type that we expect. + assert isinstance(response, ga_metric.MetricDescriptor) assert response.name == "name_value" @@ -1716,18 +1750,21 @@ def test_create_metric_descriptor_from_dict(): @pytest.mark.asyncio -async def test_create_metric_descriptor_async(transport: str = "grpc_asyncio"): +async def test_create_metric_descriptor_async( + transport: str = "grpc_asyncio", + request_type=metric_service.CreateMetricDescriptorRequest, +): client = MetricServiceAsyncClient( 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 = metric_service.CreateMetricDescriptorRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_metric_descriptor), "__call__" + type(client.transport.create_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1748,7 +1785,7 @@ async def test_create_metric_descriptor_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.CreateMetricDescriptorRequest() # Establish that the response is the type that we expect. assert isinstance(response, ga_metric.MetricDescriptor) @@ -1768,6 +1805,11 @@ async def test_create_metric_descriptor_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_create_metric_descriptor_async_from_dict(): + await test_create_metric_descriptor_async(request_type=dict) + + def test_create_metric_descriptor_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1778,7 +1820,7 @@ def test_create_metric_descriptor_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_metric_descriptor), "__call__" + type(client.transport.create_metric_descriptor), "__call__" ) as call: call.return_value = ga_metric.MetricDescriptor() @@ -1805,7 +1847,7 @@ async def test_create_metric_descriptor_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_metric_descriptor), "__call__" + type(client.transport.create_metric_descriptor), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( ga_metric.MetricDescriptor() @@ -1828,7 +1870,7 @@ def test_create_metric_descriptor_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_metric_descriptor), "__call__" + type(client.transport.create_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ga_metric.MetricDescriptor() @@ -1871,7 +1913,7 @@ async def test_create_metric_descriptor_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_metric_descriptor), "__call__" + type(client.transport.create_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ga_metric.MetricDescriptor() @@ -1925,7 +1967,7 @@ def test_delete_metric_descriptor( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_metric_descriptor), "__call__" + type(client.transport.delete_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1947,18 +1989,21 @@ def test_delete_metric_descriptor_from_dict(): @pytest.mark.asyncio -async def test_delete_metric_descriptor_async(transport: str = "grpc_asyncio"): +async def test_delete_metric_descriptor_async( + transport: str = "grpc_asyncio", + request_type=metric_service.DeleteMetricDescriptorRequest, +): client = MetricServiceAsyncClient( 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 = metric_service.DeleteMetricDescriptorRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_metric_descriptor), "__call__" + type(client.transport.delete_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1969,12 +2014,17 @@ async def test_delete_metric_descriptor_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.DeleteMetricDescriptorRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_metric_descriptor_async_from_dict(): + await test_delete_metric_descriptor_async(request_type=dict) + + def test_delete_metric_descriptor_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1985,7 +2035,7 @@ def test_delete_metric_descriptor_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_metric_descriptor), "__call__" + type(client.transport.delete_metric_descriptor), "__call__" ) as call: call.return_value = None @@ -2012,7 +2062,7 @@ async def test_delete_metric_descriptor_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_metric_descriptor), "__call__" + type(client.transport.delete_metric_descriptor), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2033,7 +2083,7 @@ def test_delete_metric_descriptor_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_metric_descriptor), "__call__" + type(client.transport.delete_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2067,7 +2117,7 @@ async def test_delete_metric_descriptor_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_metric_descriptor), "__call__" + type(client.transport.delete_metric_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2109,9 +2159,7 @@ def test_list_time_series( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListTimeSeriesResponse( next_page_token="next_page_token_value", @@ -2126,6 +2174,7 @@ def test_list_time_series( assert args[0] == metric_service.ListTimeSeriesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTimeSeriesPager) assert response.next_page_token == "next_page_token_value" @@ -2136,19 +2185,19 @@ def test_list_time_series_from_dict(): @pytest.mark.asyncio -async def test_list_time_series_async(transport: str = "grpc_asyncio"): +async def test_list_time_series_async( + transport: str = "grpc_asyncio", request_type=metric_service.ListTimeSeriesRequest +): client = MetricServiceAsyncClient( 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 = metric_service.ListTimeSeriesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( metric_service.ListTimeSeriesResponse( @@ -2162,7 +2211,7 @@ async def test_list_time_series_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.ListTimeSeriesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListTimeSeriesAsyncPager) @@ -2170,6 +2219,11 @@ async def test_list_time_series_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_time_series_async_from_dict(): + await test_list_time_series_async(request_type=dict) + + def test_list_time_series_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2179,9 +2233,7 @@ def test_list_time_series_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.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: call.return_value = metric_service.ListTimeSeriesResponse() client.list_time_series(request) @@ -2206,9 +2258,7 @@ async def test_list_time_series_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.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( metric_service.ListTimeSeriesResponse() ) @@ -2229,9 +2279,7 @@ def test_list_time_series_flattened(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListTimeSeriesResponse() @@ -2282,9 +2330,7 @@ async def test_list_time_series_flattened_async(): client = MetricServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = metric_service.ListTimeSeriesResponse() @@ -2338,9 +2384,7 @@ def test_list_time_series_pager(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( metric_service.ListTimeSeriesResponse( @@ -2380,9 +2424,7 @@ def test_list_time_series_pages(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.list_time_series), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_time_series), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( metric_service.ListTimeSeriesResponse( @@ -2415,9 +2457,7 @@ async def test_list_time_series_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_time_series), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_time_series), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2456,9 +2496,7 @@ async def test_list_time_series_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_time_series), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_time_series), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2501,7 +2539,7 @@ def test_create_time_series( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_time_series), "__call__" + type(client.transport.create_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2523,18 +2561,20 @@ def test_create_time_series_from_dict(): @pytest.mark.asyncio -async def test_create_time_series_async(transport: str = "grpc_asyncio"): +async def test_create_time_series_async( + transport: str = "grpc_asyncio", request_type=metric_service.CreateTimeSeriesRequest +): client = MetricServiceAsyncClient( 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 = metric_service.CreateTimeSeriesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_time_series), "__call__" + type(client.transport.create_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2545,12 +2585,17 @@ async def test_create_time_series_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == metric_service.CreateTimeSeriesRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_create_time_series_async_from_dict(): + await test_create_time_series_async(request_type=dict) + + def test_create_time_series_field_headers(): client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -2561,7 +2606,7 @@ def test_create_time_series_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_time_series), "__call__" + type(client.transport.create_time_series), "__call__" ) as call: call.return_value = None @@ -2588,7 +2633,7 @@ async def test_create_time_series_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_time_series), "__call__" + type(client.transport.create_time_series), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2609,7 +2654,7 @@ def test_create_time_series_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_time_series), "__call__" + type(client.transport.create_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2656,7 +2701,7 @@ async def test_create_time_series_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_time_series), "__call__" + type(client.transport.create_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2735,7 +2780,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = MetricServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2771,7 +2816,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = MetricServiceClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.MetricServiceGrpcTransport,) + assert isinstance(client.transport, transports.MetricServiceGrpcTransport,) def test_metric_service_base_transport_error(): @@ -2887,7 +2932,7 @@ def test_metric_service_host_no_port(): api_endpoint="monitoring.googleapis.com" ), ) - assert client._transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_metric_service_host_with_port(): @@ -2897,7 +2942,7 @@ def test_metric_service_host_with_port(): api_endpoint="monitoring.googleapis.com:8000" ), ) - assert client._transport._host == "monitoring.googleapis.com:8000" + assert client.transport._host == "monitoring.googleapis.com:8000" def test_metric_service_grpc_transport_channel(): @@ -2909,6 +2954,7 @@ def test_metric_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_metric_service_grpc_asyncio_transport_channel(): @@ -2920,6 +2966,7 @@ def test_metric_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( @@ -2968,8 +3015,13 @@ def test_metric_service_transport_channel_mtls_with_client_cert_source(transport ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -3013,50 +3065,84 @@ def test_metric_service_transport_channel_mtls_with_adc(transport_class): ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel -def test_common_project_path(): +"""def test_metric_descriptor_path(): project = "squid" - expected = "projects/{project}".format(project=project,) - actual = MetricServiceClient.common_project_path(project) + expected = "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(project=project, ) + actual = MetricServiceClient.metric_descriptor_path(project) assert expected == actual -def test_parse_common_project_path(): +def test_parse_metric_descriptor_path(): expected = { - "project": "clam", + "project": "clam", + } - path = MetricServiceClient.common_project_path(**expected) + path = MetricServiceClient.metric_descriptor_path(**expected) # Check that the path construction is reversible. - actual = MetricServiceClient.parse_common_project_path(path) + actual = MetricServiceClient.parse_metric_descriptor_path(path) assert expected == actual +""" -def test_common_organization_path(): - organization = "whelk" - expected = "organizations/{organization}".format(organization=organization,) - actual = MetricServiceClient.common_organization_path(organization) +def test_monitored_resource_descriptor_path(): + project = "whelk" + monitored_resource_descriptor = "octopus" + + expected = "projects/{project}/monitoredResourceDescriptors/{monitored_resource_descriptor}".format( + project=project, monitored_resource_descriptor=monitored_resource_descriptor, + ) + actual = MetricServiceClient.monitored_resource_descriptor_path( + project, monitored_resource_descriptor + ) assert expected == actual -def test_parse_common_organization_path(): +def test_parse_monitored_resource_descriptor_path(): expected = { - "organization": "octopus", + "project": "oyster", + "monitored_resource_descriptor": "nudibranch", } - path = MetricServiceClient.common_organization_path(**expected) + path = MetricServiceClient.monitored_resource_descriptor_path(**expected) # Check that the path construction is reversible. - actual = MetricServiceClient.parse_common_organization_path(path) + actual = MetricServiceClient.parse_monitored_resource_descriptor_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "cuttlefish" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = MetricServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = MetricServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = MetricServiceClient.parse_common_billing_account_path(path) assert expected == actual def test_common_folder_path(): - folder = "oyster" + folder = "winkle" expected = "folders/{folder}".format(folder=folder,) actual = MetricServiceClient.common_folder_path(folder) @@ -3065,7 +3151,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "nudibranch", + "folder": "nautilus", } path = MetricServiceClient.common_folder_path(**expected) @@ -3074,30 +3160,47 @@ def test_parse_common_folder_path(): assert expected == actual -def test_common_billing_account_path(): - billing_account = "cuttlefish" +def test_common_organization_path(): + organization = "scallop" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = MetricServiceClient.common_billing_account_path(billing_account) + expected = "organizations/{organization}".format(organization=organization,) + actual = MetricServiceClient.common_organization_path(organization) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_common_organization_path(): expected = { - "billing_account": "mussel", + "organization": "abalone", } - path = MetricServiceClient.common_billing_account_path(**expected) + path = MetricServiceClient.common_organization_path(**expected) # Check that the path construction is reversible. - actual = MetricServiceClient.parse_common_billing_account_path(path) + actual = MetricServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "squid" + + expected = "projects/{project}".format(project=project,) + actual = MetricServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = MetricServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = MetricServiceClient.parse_common_project_path(path) assert expected == actual def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "whelk" + location = "octopus" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -3108,8 +3211,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "oyster", + "location": "nudibranch", } path = MetricServiceClient.common_location_path(**expected) diff --git a/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py b/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py index 8ed40308..7d063d04 100644 --- a/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py +++ b/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py @@ -109,12 +109,12 @@ def test_notification_channel_service_client_from_service_account_file(client_cl ) 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 == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_notification_channel_service_client_get_transport_class(): @@ -492,7 +492,7 @@ def test_list_notification_channel_descriptors( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channel_descriptors), "__call__" + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_service.ListNotificationChannelDescriptorsResponse( @@ -510,6 +510,7 @@ def test_list_notification_channel_descriptors( ) # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListNotificationChannelDescriptorsPager) assert response.next_page_token == "next_page_token_value" @@ -522,6 +523,7 @@ def test_list_notification_channel_descriptors_from_dict(): @pytest.mark.asyncio async def test_list_notification_channel_descriptors_async( transport: str = "grpc_asyncio", + request_type=notification_service.ListNotificationChannelDescriptorsRequest, ): client = NotificationChannelServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -529,12 +531,11 @@ async def test_list_notification_channel_descriptors_async( # 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 = notification_service.ListNotificationChannelDescriptorsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channel_descriptors), - "__call__", + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -549,7 +550,9 @@ async def test_list_notification_channel_descriptors_async( assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert ( + args[0] == notification_service.ListNotificationChannelDescriptorsRequest() + ) # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListNotificationChannelDescriptorsAsyncPager) @@ -557,6 +560,11 @@ async def test_list_notification_channel_descriptors_async( assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_notification_channel_descriptors_async_from_dict(): + await test_list_notification_channel_descriptors_async(request_type=dict) + + def test_list_notification_channel_descriptors_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -569,7 +577,7 @@ def test_list_notification_channel_descriptors_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channel_descriptors), "__call__" + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: call.return_value = ( notification_service.ListNotificationChannelDescriptorsResponse() @@ -600,8 +608,7 @@ async def test_list_notification_channel_descriptors_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channel_descriptors), - "__call__", + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification_service.ListNotificationChannelDescriptorsResponse() @@ -626,7 +633,7 @@ def test_list_notification_channel_descriptors_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channel_descriptors), "__call__" + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ( @@ -667,8 +674,7 @@ async def test_list_notification_channel_descriptors_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channel_descriptors), - "__call__", + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ( @@ -714,7 +720,7 @@ def test_list_notification_channel_descriptors_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channel_descriptors), "__call__" + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -764,7 +770,7 @@ def test_list_notification_channel_descriptors_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channel_descriptors), "__call__" + type(client.transport.list_notification_channel_descriptors), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -804,7 +810,7 @@ async def test_list_notification_channel_descriptors_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channel_descriptors), + type(client.transport.list_notification_channel_descriptors), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -853,7 +859,7 @@ async def test_list_notification_channel_descriptors_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channel_descriptors), + type(client.transport.list_notification_channel_descriptors), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -905,7 +911,7 @@ def test_get_notification_channel_descriptor( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel_descriptor), "__call__" + type(client.transport.get_notification_channel_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannelDescriptor( @@ -925,6 +931,7 @@ def test_get_notification_channel_descriptor( assert args[0] == notification_service.GetNotificationChannelDescriptorRequest() # Establish that the response is the type that we expect. + assert isinstance(response, notification.NotificationChannelDescriptor) assert response.name == "name_value" @@ -945,6 +952,7 @@ def test_get_notification_channel_descriptor_from_dict(): @pytest.mark.asyncio async def test_get_notification_channel_descriptor_async( transport: str = "grpc_asyncio", + request_type=notification_service.GetNotificationChannelDescriptorRequest, ): client = NotificationChannelServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -952,11 +960,11 @@ async def test_get_notification_channel_descriptor_async( # 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 = notification_service.GetNotificationChannelDescriptorRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel_descriptor), "__call__" + type(client.transport.get_notification_channel_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -975,7 +983,7 @@ async def test_get_notification_channel_descriptor_async( assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == notification_service.GetNotificationChannelDescriptorRequest() # Establish that the response is the type that we expect. assert isinstance(response, notification.NotificationChannelDescriptor) @@ -991,6 +999,11 @@ async def test_get_notification_channel_descriptor_async( assert response.supported_tiers == [common.ServiceTier.SERVICE_TIER_BASIC] +@pytest.mark.asyncio +async def test_get_notification_channel_descriptor_async_from_dict(): + await test_get_notification_channel_descriptor_async(request_type=dict) + + def test_get_notification_channel_descriptor_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1003,7 +1016,7 @@ def test_get_notification_channel_descriptor_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel_descriptor), "__call__" + type(client.transport.get_notification_channel_descriptor), "__call__" ) as call: call.return_value = notification.NotificationChannelDescriptor() @@ -1032,7 +1045,7 @@ async def test_get_notification_channel_descriptor_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel_descriptor), "__call__" + type(client.transport.get_notification_channel_descriptor), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification.NotificationChannelDescriptor() @@ -1057,7 +1070,7 @@ def test_get_notification_channel_descriptor_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel_descriptor), "__call__" + type(client.transport.get_notification_channel_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannelDescriptor() @@ -1096,7 +1109,7 @@ async def test_get_notification_channel_descriptor_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel_descriptor), "__call__" + type(client.transport.get_notification_channel_descriptor), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannelDescriptor() @@ -1145,7 +1158,7 @@ def test_list_notification_channels( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_service.ListNotificationChannelsResponse( @@ -1161,6 +1174,7 @@ def test_list_notification_channels( assert args[0] == notification_service.ListNotificationChannelsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListNotificationChannelsPager) assert response.next_page_token == "next_page_token_value" @@ -1171,18 +1185,21 @@ def test_list_notification_channels_from_dict(): @pytest.mark.asyncio -async def test_list_notification_channels_async(transport: str = "grpc_asyncio"): +async def test_list_notification_channels_async( + transport: str = "grpc_asyncio", + request_type=notification_service.ListNotificationChannelsRequest, +): client = NotificationChannelServiceAsyncClient( 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 = notification_service.ListNotificationChannelsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1197,7 +1214,7 @@ async def test_list_notification_channels_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == notification_service.ListNotificationChannelsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListNotificationChannelsAsyncPager) @@ -1205,6 +1222,11 @@ async def test_list_notification_channels_async(transport: str = "grpc_asyncio") assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_notification_channels_async_from_dict(): + await test_list_notification_channels_async(request_type=dict) + + def test_list_notification_channels_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1217,7 +1239,7 @@ def test_list_notification_channels_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: call.return_value = notification_service.ListNotificationChannelsResponse() @@ -1246,7 +1268,7 @@ async def test_list_notification_channels_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification_service.ListNotificationChannelsResponse() @@ -1271,7 +1293,7 @@ def test_list_notification_channels_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_service.ListNotificationChannelsResponse() @@ -1309,7 +1331,7 @@ async def test_list_notification_channels_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_service.ListNotificationChannelsResponse() @@ -1350,7 +1372,7 @@ def test_list_notification_channels_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1398,7 +1420,7 @@ def test_list_notification_channels_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_channels), "__call__" + type(client.transport.list_notification_channels), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1438,7 +1460,7 @@ async def test_list_notification_channels_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channels), + type(client.transport.list_notification_channels), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1485,7 +1507,7 @@ async def test_list_notification_channels_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_channels), + type(client.transport.list_notification_channels), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1535,7 +1557,7 @@ def test_get_notification_channel( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel), "__call__" + type(client.transport.get_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel( @@ -1555,6 +1577,7 @@ def test_get_notification_channel( assert args[0] == notification_service.GetNotificationChannelRequest() # Establish that the response is the type that we expect. + assert isinstance(response, notification.NotificationChannel) assert response.type_ == "type__value" @@ -1576,18 +1599,21 @@ def test_get_notification_channel_from_dict(): @pytest.mark.asyncio -async def test_get_notification_channel_async(transport: str = "grpc_asyncio"): +async def test_get_notification_channel_async( + transport: str = "grpc_asyncio", + request_type=notification_service.GetNotificationChannelRequest, +): client = NotificationChannelServiceAsyncClient( 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 = notification_service.GetNotificationChannelRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel), "__call__" + type(client.transport.get_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1606,7 +1632,7 @@ async def test_get_notification_channel_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == notification_service.GetNotificationChannelRequest() # Establish that the response is the type that we expect. assert isinstance(response, notification.NotificationChannel) @@ -1625,6 +1651,11 @@ async def test_get_notification_channel_async(transport: str = "grpc_asyncio"): ) +@pytest.mark.asyncio +async def test_get_notification_channel_async_from_dict(): + await test_get_notification_channel_async(request_type=dict) + + def test_get_notification_channel_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1637,7 +1668,7 @@ def test_get_notification_channel_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel), "__call__" + type(client.transport.get_notification_channel), "__call__" ) as call: call.return_value = notification.NotificationChannel() @@ -1666,7 +1697,7 @@ async def test_get_notification_channel_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel), "__call__" + type(client.transport.get_notification_channel), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification.NotificationChannel() @@ -1691,7 +1722,7 @@ def test_get_notification_channel_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel), "__call__" + type(client.transport.get_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -1729,7 +1760,7 @@ async def test_get_notification_channel_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel), "__call__" + type(client.transport.get_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -1777,7 +1808,7 @@ def test_create_notification_channel( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_channel), "__call__" + type(client.transport.create_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel( @@ -1797,6 +1828,7 @@ def test_create_notification_channel( assert args[0] == notification_service.CreateNotificationChannelRequest() # Establish that the response is the type that we expect. + assert isinstance(response, notification.NotificationChannel) assert response.type_ == "type__value" @@ -1818,18 +1850,21 @@ def test_create_notification_channel_from_dict(): @pytest.mark.asyncio -async def test_create_notification_channel_async(transport: str = "grpc_asyncio"): +async def test_create_notification_channel_async( + transport: str = "grpc_asyncio", + request_type=notification_service.CreateNotificationChannelRequest, +): client = NotificationChannelServiceAsyncClient( 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 = notification_service.CreateNotificationChannelRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_channel), "__call__" + type(client.transport.create_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1848,7 +1883,7 @@ async def test_create_notification_channel_async(transport: str = "grpc_asyncio" assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == notification_service.CreateNotificationChannelRequest() # Establish that the response is the type that we expect. assert isinstance(response, notification.NotificationChannel) @@ -1867,6 +1902,11 @@ async def test_create_notification_channel_async(transport: str = "grpc_asyncio" ) +@pytest.mark.asyncio +async def test_create_notification_channel_async_from_dict(): + await test_create_notification_channel_async(request_type=dict) + + def test_create_notification_channel_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1879,7 +1919,7 @@ def test_create_notification_channel_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_channel), "__call__" + type(client.transport.create_notification_channel), "__call__" ) as call: call.return_value = notification.NotificationChannel() @@ -1908,7 +1948,7 @@ async def test_create_notification_channel_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_channel), "__call__" + type(client.transport.create_notification_channel), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification.NotificationChannel() @@ -1933,7 +1973,7 @@ def test_create_notification_channel_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_channel), "__call__" + type(client.transport.create_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -1980,7 +2020,7 @@ async def test_create_notification_channel_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_channel), "__call__" + type(client.transport.create_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -2037,7 +2077,7 @@ def test_update_notification_channel( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_channel), "__call__" + type(client.transport.update_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel( @@ -2057,6 +2097,7 @@ def test_update_notification_channel( assert args[0] == notification_service.UpdateNotificationChannelRequest() # Establish that the response is the type that we expect. + assert isinstance(response, notification.NotificationChannel) assert response.type_ == "type__value" @@ -2078,18 +2119,21 @@ def test_update_notification_channel_from_dict(): @pytest.mark.asyncio -async def test_update_notification_channel_async(transport: str = "grpc_asyncio"): +async def test_update_notification_channel_async( + transport: str = "grpc_asyncio", + request_type=notification_service.UpdateNotificationChannelRequest, +): client = NotificationChannelServiceAsyncClient( 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 = notification_service.UpdateNotificationChannelRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_channel), "__call__" + type(client.transport.update_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2108,7 +2152,7 @@ async def test_update_notification_channel_async(transport: str = "grpc_asyncio" assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == notification_service.UpdateNotificationChannelRequest() # Establish that the response is the type that we expect. assert isinstance(response, notification.NotificationChannel) @@ -2127,6 +2171,11 @@ async def test_update_notification_channel_async(transport: str = "grpc_asyncio" ) +@pytest.mark.asyncio +async def test_update_notification_channel_async_from_dict(): + await test_update_notification_channel_async(request_type=dict) + + def test_update_notification_channel_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2139,7 +2188,7 @@ def test_update_notification_channel_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_channel), "__call__" + type(client.transport.update_notification_channel), "__call__" ) as call: call.return_value = notification.NotificationChannel() @@ -2171,7 +2220,7 @@ async def test_update_notification_channel_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_channel), "__call__" + type(client.transport.update_notification_channel), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification.NotificationChannel() @@ -2199,7 +2248,7 @@ def test_update_notification_channel_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_channel), "__call__" + type(client.transport.update_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -2246,7 +2295,7 @@ async def test_update_notification_channel_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_channel), "__call__" + type(client.transport.update_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -2303,7 +2352,7 @@ def test_delete_notification_channel( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_channel), "__call__" + type(client.transport.delete_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2325,18 +2374,21 @@ def test_delete_notification_channel_from_dict(): @pytest.mark.asyncio -async def test_delete_notification_channel_async(transport: str = "grpc_asyncio"): +async def test_delete_notification_channel_async( + transport: str = "grpc_asyncio", + request_type=notification_service.DeleteNotificationChannelRequest, +): client = NotificationChannelServiceAsyncClient( 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 = notification_service.DeleteNotificationChannelRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_channel), "__call__" + type(client.transport.delete_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2347,12 +2399,17 @@ async def test_delete_notification_channel_async(transport: str = "grpc_asyncio" assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == notification_service.DeleteNotificationChannelRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_notification_channel_async_from_dict(): + await test_delete_notification_channel_async(request_type=dict) + + def test_delete_notification_channel_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2365,7 +2422,7 @@ def test_delete_notification_channel_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_channel), "__call__" + type(client.transport.delete_notification_channel), "__call__" ) as call: call.return_value = None @@ -2394,7 +2451,7 @@ async def test_delete_notification_channel_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_channel), "__call__" + type(client.transport.delete_notification_channel), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2417,7 +2474,7 @@ def test_delete_notification_channel_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_channel), "__call__" + type(client.transport.delete_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2461,7 +2518,7 @@ async def test_delete_notification_channel_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_channel), "__call__" + type(client.transport.delete_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2513,7 +2570,7 @@ def test_send_notification_channel_verification_code( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.send_notification_channel_verification_code), "__call__" + type(client.transport.send_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2540,6 +2597,7 @@ def test_send_notification_channel_verification_code_from_dict(): @pytest.mark.asyncio async def test_send_notification_channel_verification_code_async( transport: str = "grpc_asyncio", + request_type=notification_service.SendNotificationChannelVerificationCodeRequest, ): client = NotificationChannelServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -2547,12 +2605,11 @@ async def test_send_notification_channel_verification_code_async( # 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 = notification_service.SendNotificationChannelVerificationCodeRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.send_notification_channel_verification_code), - "__call__", + type(client.transport.send_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2563,12 +2620,20 @@ async def test_send_notification_channel_verification_code_async( assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert ( + args[0] + == notification_service.SendNotificationChannelVerificationCodeRequest() + ) # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_send_notification_channel_verification_code_async_from_dict(): + await test_send_notification_channel_verification_code_async(request_type=dict) + + def test_send_notification_channel_verification_code_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2581,7 +2646,7 @@ def test_send_notification_channel_verification_code_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.send_notification_channel_verification_code), "__call__" + type(client.transport.send_notification_channel_verification_code), "__call__" ) as call: call.return_value = None @@ -2610,8 +2675,7 @@ async def test_send_notification_channel_verification_code_field_headers_async() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.send_notification_channel_verification_code), - "__call__", + type(client.transport.send_notification_channel_verification_code), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2634,7 +2698,7 @@ def test_send_notification_channel_verification_code_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.send_notification_channel_verification_code), "__call__" + type(client.transport.send_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2673,8 +2737,7 @@ async def test_send_notification_channel_verification_code_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.send_notification_channel_verification_code), - "__call__", + type(client.transport.send_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2723,7 +2786,7 @@ def test_get_notification_channel_verification_code( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel_verification_code), "__call__" + type(client.transport.get_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_service.GetNotificationChannelVerificationCodeResponse( @@ -2742,6 +2805,7 @@ def test_get_notification_channel_verification_code( ) # Establish that the response is the type that we expect. + assert isinstance( response, notification_service.GetNotificationChannelVerificationCodeResponse ) @@ -2756,6 +2820,7 @@ def test_get_notification_channel_verification_code_from_dict(): @pytest.mark.asyncio async def test_get_notification_channel_verification_code_async( transport: str = "grpc_asyncio", + request_type=notification_service.GetNotificationChannelVerificationCodeRequest, ): client = NotificationChannelServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -2763,12 +2828,11 @@ async def test_get_notification_channel_verification_code_async( # 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 = notification_service.GetNotificationChannelVerificationCodeRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel_verification_code), - "__call__", + type(client.transport.get_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2783,7 +2847,10 @@ async def test_get_notification_channel_verification_code_async( assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert ( + args[0] + == notification_service.GetNotificationChannelVerificationCodeRequest() + ) # Establish that the response is the type that we expect. assert isinstance( @@ -2793,6 +2860,11 @@ async def test_get_notification_channel_verification_code_async( assert response.code == "code_value" +@pytest.mark.asyncio +async def test_get_notification_channel_verification_code_async_from_dict(): + await test_get_notification_channel_verification_code_async(request_type=dict) + + def test_get_notification_channel_verification_code_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2805,7 +2877,7 @@ def test_get_notification_channel_verification_code_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel_verification_code), "__call__" + type(client.transport.get_notification_channel_verification_code), "__call__" ) as call: call.return_value = ( notification_service.GetNotificationChannelVerificationCodeResponse() @@ -2836,8 +2908,7 @@ async def test_get_notification_channel_verification_code_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel_verification_code), - "__call__", + type(client.transport.get_notification_channel_verification_code), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification_service.GetNotificationChannelVerificationCodeResponse() @@ -2862,7 +2933,7 @@ def test_get_notification_channel_verification_code_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_channel_verification_code), "__call__" + type(client.transport.get_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ( @@ -2903,8 +2974,7 @@ async def test_get_notification_channel_verification_code_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_channel_verification_code), - "__call__", + type(client.transport.get_notification_channel_verification_code), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = ( @@ -2957,7 +3027,7 @@ def test_verify_notification_channel( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.verify_notification_channel), "__call__" + type(client.transport.verify_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel( @@ -2977,6 +3047,7 @@ def test_verify_notification_channel( assert args[0] == notification_service.VerifyNotificationChannelRequest() # Establish that the response is the type that we expect. + assert isinstance(response, notification.NotificationChannel) assert response.type_ == "type__value" @@ -2998,18 +3069,21 @@ def test_verify_notification_channel_from_dict(): @pytest.mark.asyncio -async def test_verify_notification_channel_async(transport: str = "grpc_asyncio"): +async def test_verify_notification_channel_async( + transport: str = "grpc_asyncio", + request_type=notification_service.VerifyNotificationChannelRequest, +): client = NotificationChannelServiceAsyncClient( 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 = notification_service.VerifyNotificationChannelRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.verify_notification_channel), "__call__" + type(client.transport.verify_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3028,7 +3102,7 @@ async def test_verify_notification_channel_async(transport: str = "grpc_asyncio" assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == notification_service.VerifyNotificationChannelRequest() # Establish that the response is the type that we expect. assert isinstance(response, notification.NotificationChannel) @@ -3047,6 +3121,11 @@ async def test_verify_notification_channel_async(transport: str = "grpc_asyncio" ) +@pytest.mark.asyncio +async def test_verify_notification_channel_async_from_dict(): + await test_verify_notification_channel_async(request_type=dict) + + def test_verify_notification_channel_field_headers(): client = NotificationChannelServiceClient( credentials=credentials.AnonymousCredentials(), @@ -3059,7 +3138,7 @@ def test_verify_notification_channel_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.verify_notification_channel), "__call__" + type(client.transport.verify_notification_channel), "__call__" ) as call: call.return_value = notification.NotificationChannel() @@ -3088,7 +3167,7 @@ async def test_verify_notification_channel_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.verify_notification_channel), "__call__" + type(client.transport.verify_notification_channel), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification.NotificationChannel() @@ -3113,7 +3192,7 @@ def test_verify_notification_channel_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.verify_notification_channel), "__call__" + type(client.transport.verify_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -3157,7 +3236,7 @@ async def test_verify_notification_channel_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.verify_notification_channel), "__call__" + type(client.transport.verify_notification_channel), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification.NotificationChannel() @@ -3233,7 +3312,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = NotificationChannelServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -3272,7 +3351,7 @@ def test_transport_grpc_default(): credentials=credentials.AnonymousCredentials(), ) assert isinstance( - client._transport, transports.NotificationChannelServiceGrpcTransport, + client.transport, transports.NotificationChannelServiceGrpcTransport, ) @@ -3388,7 +3467,7 @@ def test_notification_channel_service_host_no_port(): api_endpoint="monitoring.googleapis.com" ), ) - assert client._transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_notification_channel_service_host_with_port(): @@ -3398,7 +3477,7 @@ def test_notification_channel_service_host_with_port(): api_endpoint="monitoring.googleapis.com:8000" ), ) - assert client._transport._host == "monitoring.googleapis.com:8000" + assert client.transport._host == "monitoring.googleapis.com:8000" def test_notification_channel_service_grpc_transport_channel(): @@ -3410,6 +3489,7 @@ def test_notification_channel_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_notification_channel_service_grpc_asyncio_transport_channel(): @@ -3421,6 +3501,7 @@ def test_notification_channel_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( @@ -3470,8 +3551,13 @@ def test_notification_channel_service_transport_channel_mtls_with_client_cert_so ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -3514,6 +3600,10 @@ def test_notification_channel_service_transport_channel_mtls_with_adc(transport_ ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel @@ -3572,83 +3662,83 @@ def test_parse_notification_channel_descriptor_path(): assert expected == actual -def test_common_project_path(): - project = "winkle" +def test_common_billing_account_path(): + billing_account = "winkle" - expected = "projects/{project}".format(project=project,) - actual = NotificationChannelServiceClient.common_project_path(project) + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = NotificationChannelServiceClient.common_billing_account_path( + billing_account + ) assert expected == actual -def test_parse_common_project_path(): +def test_parse_common_billing_account_path(): expected = { - "project": "nautilus", + "billing_account": "nautilus", } - path = NotificationChannelServiceClient.common_project_path(**expected) + path = NotificationChannelServiceClient.common_billing_account_path(**expected) # Check that the path construction is reversible. - actual = NotificationChannelServiceClient.parse_common_project_path(path) + actual = NotificationChannelServiceClient.parse_common_billing_account_path(path) assert expected == actual -def test_common_organization_path(): - organization = "scallop" +def test_common_folder_path(): + folder = "scallop" - expected = "organizations/{organization}".format(organization=organization,) - actual = NotificationChannelServiceClient.common_organization_path(organization) + expected = "folders/{folder}".format(folder=folder,) + actual = NotificationChannelServiceClient.common_folder_path(folder) assert expected == actual -def test_parse_common_organization_path(): +def test_parse_common_folder_path(): expected = { - "organization": "abalone", + "folder": "abalone", } - path = NotificationChannelServiceClient.common_organization_path(**expected) + path = NotificationChannelServiceClient.common_folder_path(**expected) # Check that the path construction is reversible. - actual = NotificationChannelServiceClient.parse_common_organization_path(path) + actual = NotificationChannelServiceClient.parse_common_folder_path(path) assert expected == actual -def test_common_folder_path(): - folder = "squid" +def test_common_organization_path(): + organization = "squid" - expected = "folders/{folder}".format(folder=folder,) - actual = NotificationChannelServiceClient.common_folder_path(folder) + expected = "organizations/{organization}".format(organization=organization,) + actual = NotificationChannelServiceClient.common_organization_path(organization) assert expected == actual -def test_parse_common_folder_path(): +def test_parse_common_organization_path(): expected = { - "folder": "clam", + "organization": "clam", } - path = NotificationChannelServiceClient.common_folder_path(**expected) + path = NotificationChannelServiceClient.common_organization_path(**expected) # Check that the path construction is reversible. - actual = NotificationChannelServiceClient.parse_common_folder_path(path) + actual = NotificationChannelServiceClient.parse_common_organization_path(path) assert expected == actual -def test_common_billing_account_path(): - billing_account = "whelk" +def test_common_project_path(): + project = "whelk" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = NotificationChannelServiceClient.common_billing_account_path( - billing_account - ) + expected = "projects/{project}".format(project=project,) + actual = NotificationChannelServiceClient.common_project_path(project) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_common_project_path(): expected = { - "billing_account": "octopus", + "project": "octopus", } - path = NotificationChannelServiceClient.common_billing_account_path(**expected) + path = NotificationChannelServiceClient.common_project_path(**expected) # Check that the path construction is reversible. - actual = NotificationChannelServiceClient.parse_common_billing_account_path(path) + actual = NotificationChannelServiceClient.parse_common_project_path(path) assert expected == actual diff --git a/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py b/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py index 17fc2b1a..7ced9a3b 100644 --- a/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py +++ b/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py @@ -47,7 +47,6 @@ from google.protobuf import duration_pb2 as duration # type: ignore from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.type import calendar_period_pb2 as calendar_period # type: ignore -from google.type import calendar_period_pb2 as gt_calendar_period # type: ignore def client_cert_source_callback(): @@ -106,12 +105,12 @@ def test_service_monitoring_service_client_from_service_account_file(client_clas ) 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 == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_service_monitoring_service_client_get_transport_class(): @@ -487,7 +486,7 @@ def test_create_service( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_service), "__call__") as call: + with mock.patch.object(type(client.transport.create_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_service.Service( name="name_value", display_name="display_name_value", custom=None, @@ -502,6 +501,7 @@ def test_create_service( assert args[0] == service_service.CreateServiceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gm_service.Service) assert response.name == "name_value" @@ -514,19 +514,19 @@ def test_create_service_from_dict(): @pytest.mark.asyncio -async def test_create_service_async(transport: str = "grpc_asyncio"): +async def test_create_service_async( + transport: str = "grpc_asyncio", request_type=service_service.CreateServiceRequest +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.CreateServiceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gm_service.Service(name="name_value", display_name="display_name_value",) @@ -538,7 +538,7 @@ async def test_create_service_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.CreateServiceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gm_service.Service) @@ -548,6 +548,11 @@ async def test_create_service_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_create_service_async_from_dict(): + await test_create_service_async(request_type=dict) + + def test_create_service_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -559,7 +564,7 @@ def test_create_service_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.create_service), "__call__") as call: + with mock.patch.object(type(client.transport.create_service), "__call__") as call: call.return_value = gm_service.Service() client.create_service(request) @@ -586,9 +591,7 @@ async def test_create_service_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.create_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_service), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gm_service.Service()) await client.create_service(request) @@ -609,7 +612,7 @@ def test_create_service_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_service), "__call__") as call: + with mock.patch.object(type(client.transport.create_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_service.Service() @@ -651,9 +654,7 @@ async def test_create_service_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_service.Service() @@ -702,7 +703,7 @@ def test_get_service( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_service), "__call__") as call: + with mock.patch.object(type(client.transport.get_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.Service( name="name_value", display_name="display_name_value", custom=None, @@ -717,6 +718,7 @@ def test_get_service( assert args[0] == service_service.GetServiceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, service.Service) assert response.name == "name_value" @@ -729,19 +731,19 @@ def test_get_service_from_dict(): @pytest.mark.asyncio -async def test_get_service_async(transport: str = "grpc_asyncio"): +async def test_get_service_async( + transport: str = "grpc_asyncio", request_type=service_service.GetServiceRequest +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.GetServiceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.Service(name="name_value", display_name="display_name_value",) @@ -753,7 +755,7 @@ async def test_get_service_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.GetServiceRequest() # Establish that the response is the type that we expect. assert isinstance(response, service.Service) @@ -763,6 +765,11 @@ async def test_get_service_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_get_service_async_from_dict(): + await test_get_service_async(request_type=dict) + + def test_get_service_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -774,7 +781,7 @@ def test_get_service_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_service), "__call__") as call: + with mock.patch.object(type(client.transport.get_service), "__call__") as call: call.return_value = service.Service() client.get_service(request) @@ -801,9 +808,7 @@ async def test_get_service_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_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_service), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(service.Service()) await client.get_service(request) @@ -824,7 +829,7 @@ def test_get_service_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_service), "__call__") as call: + with mock.patch.object(type(client.transport.get_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.Service() @@ -860,9 +865,7 @@ async def test_get_service_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service.Service() @@ -905,7 +908,7 @@ def test_list_services( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_services), "__call__") as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service_service.ListServicesResponse( next_page_token="next_page_token_value", @@ -920,6 +923,7 @@ def test_list_services( assert args[0] == service_service.ListServicesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListServicesPager) assert response.next_page_token == "next_page_token_value" @@ -930,19 +934,19 @@ def test_list_services_from_dict(): @pytest.mark.asyncio -async def test_list_services_async(transport: str = "grpc_asyncio"): +async def test_list_services_async( + transport: str = "grpc_asyncio", request_type=service_service.ListServicesRequest +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.ListServicesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_services), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service_service.ListServicesResponse( @@ -956,7 +960,7 @@ async def test_list_services_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.ListServicesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListServicesAsyncPager) @@ -964,6 +968,11 @@ async def test_list_services_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_services_async_from_dict(): + await test_list_services_async(request_type=dict) + + def test_list_services_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -975,7 +984,7 @@ def test_list_services_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_services), "__call__") as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: call.return_value = service_service.ListServicesResponse() client.list_services(request) @@ -1002,9 +1011,7 @@ async def test_list_services_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_services), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service_service.ListServicesResponse() ) @@ -1027,7 +1034,7 @@ def test_list_services_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_services), "__call__") as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service_service.ListServicesResponse() @@ -1063,9 +1070,7 @@ async def test_list_services_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_services), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = service_service.ListServicesResponse() @@ -1104,7 +1109,7 @@ def test_list_services_pager(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_services), "__call__") as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( service_service.ListServicesResponse( @@ -1140,7 +1145,7 @@ def test_list_services_pages(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_services), "__call__") as call: + with mock.patch.object(type(client.transport.list_services), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( service_service.ListServicesResponse( @@ -1169,9 +1174,7 @@ async def test_list_services_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_services), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_services), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1206,9 +1209,7 @@ async def test_list_services_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_services), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_services), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1244,7 +1245,7 @@ def test_update_service( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_service), "__call__") as call: + with mock.patch.object(type(client.transport.update_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_service.Service( name="name_value", display_name="display_name_value", custom=None, @@ -1259,6 +1260,7 @@ def test_update_service( assert args[0] == service_service.UpdateServiceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gm_service.Service) assert response.name == "name_value" @@ -1271,19 +1273,19 @@ def test_update_service_from_dict(): @pytest.mark.asyncio -async def test_update_service_async(transport: str = "grpc_asyncio"): +async def test_update_service_async( + transport: str = "grpc_asyncio", request_type=service_service.UpdateServiceRequest +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.UpdateServiceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gm_service.Service(name="name_value", display_name="display_name_value",) @@ -1295,7 +1297,7 @@ async def test_update_service_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.UpdateServiceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gm_service.Service) @@ -1305,6 +1307,11 @@ async def test_update_service_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_update_service_async_from_dict(): + await test_update_service_async(request_type=dict) + + def test_update_service_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1316,7 +1323,7 @@ def test_update_service_field_headers(): request.service.name = "service.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_service), "__call__") as call: + with mock.patch.object(type(client.transport.update_service), "__call__") as call: call.return_value = gm_service.Service() client.update_service(request) @@ -1345,9 +1352,7 @@ async def test_update_service_field_headers_async(): request.service.name = "service.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_service), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gm_service.Service()) await client.update_service(request) @@ -1370,7 +1375,7 @@ def test_update_service_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_service), "__call__") as call: + with mock.patch.object(type(client.transport.update_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_service.Service() @@ -1407,9 +1412,7 @@ async def test_update_service_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gm_service.Service() @@ -1455,7 +1458,7 @@ def test_delete_service( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_service), "__call__") as call: + with mock.patch.object(type(client.transport.delete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1476,19 +1479,19 @@ def test_delete_service_from_dict(): @pytest.mark.asyncio -async def test_delete_service_async(transport: str = "grpc_asyncio"): +async def test_delete_service_async( + transport: str = "grpc_asyncio", request_type=service_service.DeleteServiceRequest +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.DeleteServiceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1498,12 +1501,17 @@ async def test_delete_service_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.DeleteServiceRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_service_async_from_dict(): + await test_delete_service_async(request_type=dict) + + def test_delete_service_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1515,7 +1523,7 @@ def test_delete_service_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_service), "__call__") as call: + with mock.patch.object(type(client.transport.delete_service), "__call__") as call: call.return_value = None client.delete_service(request) @@ -1542,9 +1550,7 @@ async def test_delete_service_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_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_service), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_service(request) @@ -1565,7 +1571,7 @@ def test_delete_service_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_service), "__call__") as call: + with mock.patch.object(type(client.transport.delete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1601,9 +1607,7 @@ async def test_delete_service_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_service), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1648,7 +1652,7 @@ def test_create_service_level_objective( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_service_level_objective), "__call__" + type(client.transport.create_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective( @@ -1667,6 +1671,7 @@ def test_create_service_level_objective( assert args[0] == service_service.CreateServiceLevelObjectiveRequest() # Establish that the response is the type that we expect. + assert isinstance(response, service.ServiceLevelObjective) assert response.name == "name_value" @@ -1681,18 +1686,21 @@ def test_create_service_level_objective_from_dict(): @pytest.mark.asyncio -async def test_create_service_level_objective_async(transport: str = "grpc_asyncio"): +async def test_create_service_level_objective_async( + transport: str = "grpc_asyncio", + request_type=service_service.CreateServiceLevelObjectiveRequest, +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.CreateServiceLevelObjectiveRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_service_level_objective), "__call__" + type(client.transport.create_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1707,7 +1715,7 @@ async def test_create_service_level_objective_async(transport: str = "grpc_async assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.CreateServiceLevelObjectiveRequest() # Establish that the response is the type that we expect. assert isinstance(response, service.ServiceLevelObjective) @@ -1719,6 +1727,11 @@ async def test_create_service_level_objective_async(transport: str = "grpc_async assert math.isclose(response.goal, 0.419, rel_tol=1e-6) +@pytest.mark.asyncio +async def test_create_service_level_objective_async_from_dict(): + await test_create_service_level_objective_async(request_type=dict) + + def test_create_service_level_objective_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1731,7 +1744,7 @@ def test_create_service_level_objective_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_service_level_objective), "__call__" + type(client.transport.create_service_level_objective), "__call__" ) as call: call.return_value = service.ServiceLevelObjective() @@ -1760,7 +1773,7 @@ async def test_create_service_level_objective_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_service_level_objective), "__call__" + type(client.transport.create_service_level_objective), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ServiceLevelObjective() @@ -1785,7 +1798,7 @@ def test_create_service_level_objective_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_service_level_objective), "__call__" + type(client.transport.create_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective() @@ -1832,7 +1845,7 @@ async def test_create_service_level_objective_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_service_level_objective), "__call__" + type(client.transport.create_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective() @@ -1889,7 +1902,7 @@ def test_get_service_level_objective( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_service_level_objective), "__call__" + type(client.transport.get_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective( @@ -1908,6 +1921,7 @@ def test_get_service_level_objective( assert args[0] == service_service.GetServiceLevelObjectiveRequest() # Establish that the response is the type that we expect. + assert isinstance(response, service.ServiceLevelObjective) assert response.name == "name_value" @@ -1922,18 +1936,21 @@ def test_get_service_level_objective_from_dict(): @pytest.mark.asyncio -async def test_get_service_level_objective_async(transport: str = "grpc_asyncio"): +async def test_get_service_level_objective_async( + transport: str = "grpc_asyncio", + request_type=service_service.GetServiceLevelObjectiveRequest, +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.GetServiceLevelObjectiveRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_service_level_objective), "__call__" + type(client.transport.get_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1948,7 +1965,7 @@ async def test_get_service_level_objective_async(transport: str = "grpc_asyncio" assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.GetServiceLevelObjectiveRequest() # Establish that the response is the type that we expect. assert isinstance(response, service.ServiceLevelObjective) @@ -1960,6 +1977,11 @@ async def test_get_service_level_objective_async(transport: str = "grpc_asyncio" assert math.isclose(response.goal, 0.419, rel_tol=1e-6) +@pytest.mark.asyncio +async def test_get_service_level_objective_async_from_dict(): + await test_get_service_level_objective_async(request_type=dict) + + def test_get_service_level_objective_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1972,7 +1994,7 @@ def test_get_service_level_objective_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_service_level_objective), "__call__" + type(client.transport.get_service_level_objective), "__call__" ) as call: call.return_value = service.ServiceLevelObjective() @@ -2001,7 +2023,7 @@ async def test_get_service_level_objective_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_service_level_objective), "__call__" + type(client.transport.get_service_level_objective), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ServiceLevelObjective() @@ -2026,7 +2048,7 @@ def test_get_service_level_objective_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_service_level_objective), "__call__" + type(client.transport.get_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective() @@ -2064,7 +2086,7 @@ async def test_get_service_level_objective_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_service_level_objective), "__call__" + type(client.transport.get_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective() @@ -2112,7 +2134,7 @@ def test_list_service_level_objectives( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service_service.ListServiceLevelObjectivesResponse( @@ -2128,6 +2150,7 @@ def test_list_service_level_objectives( assert args[0] == service_service.ListServiceLevelObjectivesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListServiceLevelObjectivesPager) assert response.next_page_token == "next_page_token_value" @@ -2138,18 +2161,21 @@ def test_list_service_level_objectives_from_dict(): @pytest.mark.asyncio -async def test_list_service_level_objectives_async(transport: str = "grpc_asyncio"): +async def test_list_service_level_objectives_async( + transport: str = "grpc_asyncio", + request_type=service_service.ListServiceLevelObjectivesRequest, +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.ListServiceLevelObjectivesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2164,7 +2190,7 @@ async def test_list_service_level_objectives_async(transport: str = "grpc_asynci assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.ListServiceLevelObjectivesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListServiceLevelObjectivesAsyncPager) @@ -2172,6 +2198,11 @@ async def test_list_service_level_objectives_async(transport: str = "grpc_asynci assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_service_level_objectives_async_from_dict(): + await test_list_service_level_objectives_async(request_type=dict) + + def test_list_service_level_objectives_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2184,7 +2215,7 @@ def test_list_service_level_objectives_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: call.return_value = service_service.ListServiceLevelObjectivesResponse() @@ -2213,7 +2244,7 @@ async def test_list_service_level_objectives_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service_service.ListServiceLevelObjectivesResponse() @@ -2238,7 +2269,7 @@ def test_list_service_level_objectives_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service_service.ListServiceLevelObjectivesResponse() @@ -2276,7 +2307,7 @@ async def test_list_service_level_objectives_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service_service.ListServiceLevelObjectivesResponse() @@ -2317,7 +2348,7 @@ def test_list_service_level_objectives_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2365,7 +2396,7 @@ def test_list_service_level_objectives_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_service_level_objectives), "__call__" + type(client.transport.list_service_level_objectives), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2405,7 +2436,7 @@ async def test_list_service_level_objectives_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_service_level_objectives), + type(client.transport.list_service_level_objectives), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2452,7 +2483,7 @@ async def test_list_service_level_objectives_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_service_level_objectives), + type(client.transport.list_service_level_objectives), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2504,7 +2535,7 @@ def test_update_service_level_objective( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_service_level_objective), "__call__" + type(client.transport.update_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective( @@ -2523,6 +2554,7 @@ def test_update_service_level_objective( assert args[0] == service_service.UpdateServiceLevelObjectiveRequest() # Establish that the response is the type that we expect. + assert isinstance(response, service.ServiceLevelObjective) assert response.name == "name_value" @@ -2537,18 +2569,21 @@ def test_update_service_level_objective_from_dict(): @pytest.mark.asyncio -async def test_update_service_level_objective_async(transport: str = "grpc_asyncio"): +async def test_update_service_level_objective_async( + transport: str = "grpc_asyncio", + request_type=service_service.UpdateServiceLevelObjectiveRequest, +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.UpdateServiceLevelObjectiveRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_service_level_objective), "__call__" + type(client.transport.update_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2563,7 +2598,7 @@ async def test_update_service_level_objective_async(transport: str = "grpc_async assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.UpdateServiceLevelObjectiveRequest() # Establish that the response is the type that we expect. assert isinstance(response, service.ServiceLevelObjective) @@ -2575,6 +2610,11 @@ async def test_update_service_level_objective_async(transport: str = "grpc_async assert math.isclose(response.goal, 0.419, rel_tol=1e-6) +@pytest.mark.asyncio +async def test_update_service_level_objective_async_from_dict(): + await test_update_service_level_objective_async(request_type=dict) + + def test_update_service_level_objective_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2587,7 +2627,7 @@ def test_update_service_level_objective_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_service_level_objective), "__call__" + type(client.transport.update_service_level_objective), "__call__" ) as call: call.return_value = service.ServiceLevelObjective() @@ -2619,7 +2659,7 @@ async def test_update_service_level_objective_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_service_level_objective), "__call__" + type(client.transport.update_service_level_objective), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service.ServiceLevelObjective() @@ -2647,7 +2687,7 @@ def test_update_service_level_objective_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_service_level_objective), "__call__" + type(client.transport.update_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective() @@ -2690,7 +2730,7 @@ async def test_update_service_level_objective_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_service_level_objective), "__call__" + type(client.transport.update_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = service.ServiceLevelObjective() @@ -2743,7 +2783,7 @@ def test_delete_service_level_objective( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_service_level_objective), "__call__" + type(client.transport.delete_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2765,18 +2805,21 @@ def test_delete_service_level_objective_from_dict(): @pytest.mark.asyncio -async def test_delete_service_level_objective_async(transport: str = "grpc_asyncio"): +async def test_delete_service_level_objective_async( + transport: str = "grpc_asyncio", + request_type=service_service.DeleteServiceLevelObjectiveRequest, +): client = ServiceMonitoringServiceAsyncClient( 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 = service_service.DeleteServiceLevelObjectiveRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_service_level_objective), "__call__" + type(client.transport.delete_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2787,12 +2830,17 @@ async def test_delete_service_level_objective_async(transport: str = "grpc_async assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == service_service.DeleteServiceLevelObjectiveRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_service_level_objective_async_from_dict(): + await test_delete_service_level_objective_async(request_type=dict) + + def test_delete_service_level_objective_field_headers(): client = ServiceMonitoringServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2805,7 +2853,7 @@ def test_delete_service_level_objective_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_service_level_objective), "__call__" + type(client.transport.delete_service_level_objective), "__call__" ) as call: call.return_value = None @@ -2834,7 +2882,7 @@ async def test_delete_service_level_objective_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_service_level_objective), "__call__" + type(client.transport.delete_service_level_objective), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -2857,7 +2905,7 @@ def test_delete_service_level_objective_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_service_level_objective), "__call__" + type(client.transport.delete_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2895,7 +2943,7 @@ async def test_delete_service_level_objective_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_service_level_objective), "__call__" + type(client.transport.delete_service_level_objective), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2963,7 +3011,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = ServiceMonitoringServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -3002,7 +3050,7 @@ def test_transport_grpc_default(): credentials=credentials.AnonymousCredentials(), ) assert isinstance( - client._transport, transports.ServiceMonitoringServiceGrpcTransport, + client.transport, transports.ServiceMonitoringServiceGrpcTransport, ) @@ -3118,7 +3166,7 @@ def test_service_monitoring_service_host_no_port(): api_endpoint="monitoring.googleapis.com" ), ) - assert client._transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_service_monitoring_service_host_with_port(): @@ -3128,7 +3176,7 @@ def test_service_monitoring_service_host_with_port(): api_endpoint="monitoring.googleapis.com:8000" ), ) - assert client._transport._host == "monitoring.googleapis.com:8000" + assert client.transport._host == "monitoring.googleapis.com:8000" def test_service_monitoring_service_grpc_transport_channel(): @@ -3140,6 +3188,7 @@ def test_service_monitoring_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_service_monitoring_service_grpc_asyncio_transport_channel(): @@ -3151,6 +3200,7 @@ def test_service_monitoring_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( @@ -3200,8 +3250,13 @@ def test_service_monitoring_service_transport_channel_mtls_with_client_cert_sour ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -3244,6 +3299,10 @@ def test_service_monitoring_service_transport_channel_mtls_with_adc(transport_cl ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel @@ -3300,81 +3359,81 @@ def test_parse_service_level_objective_path(): assert expected == actual -def test_common_project_path(): - project = "scallop" +def test_common_billing_account_path(): + billing_account = "scallop" - expected = "projects/{project}".format(project=project,) - actual = ServiceMonitoringServiceClient.common_project_path(project) + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = ServiceMonitoringServiceClient.common_billing_account_path(billing_account) assert expected == actual -def test_parse_common_project_path(): +def test_parse_common_billing_account_path(): expected = { - "project": "abalone", + "billing_account": "abalone", } - path = ServiceMonitoringServiceClient.common_project_path(**expected) + path = ServiceMonitoringServiceClient.common_billing_account_path(**expected) # Check that the path construction is reversible. - actual = ServiceMonitoringServiceClient.parse_common_project_path(path) + actual = ServiceMonitoringServiceClient.parse_common_billing_account_path(path) assert expected == actual -def test_common_organization_path(): - organization = "squid" +def test_common_folder_path(): + folder = "squid" - expected = "organizations/{organization}".format(organization=organization,) - actual = ServiceMonitoringServiceClient.common_organization_path(organization) + expected = "folders/{folder}".format(folder=folder,) + actual = ServiceMonitoringServiceClient.common_folder_path(folder) assert expected == actual -def test_parse_common_organization_path(): +def test_parse_common_folder_path(): expected = { - "organization": "clam", + "folder": "clam", } - path = ServiceMonitoringServiceClient.common_organization_path(**expected) + path = ServiceMonitoringServiceClient.common_folder_path(**expected) # Check that the path construction is reversible. - actual = ServiceMonitoringServiceClient.parse_common_organization_path(path) + actual = ServiceMonitoringServiceClient.parse_common_folder_path(path) assert expected == actual -def test_common_folder_path(): - folder = "whelk" +def test_common_organization_path(): + organization = "whelk" - expected = "folders/{folder}".format(folder=folder,) - actual = ServiceMonitoringServiceClient.common_folder_path(folder) + expected = "organizations/{organization}".format(organization=organization,) + actual = ServiceMonitoringServiceClient.common_organization_path(organization) assert expected == actual -def test_parse_common_folder_path(): +def test_parse_common_organization_path(): expected = { - "folder": "octopus", + "organization": "octopus", } - path = ServiceMonitoringServiceClient.common_folder_path(**expected) + path = ServiceMonitoringServiceClient.common_organization_path(**expected) # Check that the path construction is reversible. - actual = ServiceMonitoringServiceClient.parse_common_folder_path(path) + actual = ServiceMonitoringServiceClient.parse_common_organization_path(path) assert expected == actual -def test_common_billing_account_path(): - billing_account = "oyster" +def test_common_project_path(): + project = "oyster" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = ServiceMonitoringServiceClient.common_billing_account_path(billing_account) + expected = "projects/{project}".format(project=project,) + actual = ServiceMonitoringServiceClient.common_project_path(project) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_common_project_path(): expected = { - "billing_account": "nudibranch", + "project": "nudibranch", } - path = ServiceMonitoringServiceClient.common_billing_account_path(**expected) + path = ServiceMonitoringServiceClient.common_project_path(**expected) # Check that the path construction is reversible. - actual = ServiceMonitoringServiceClient.parse_common_billing_account_path(path) + actual = ServiceMonitoringServiceClient.parse_common_project_path(path) assert expected == actual diff --git a/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py b/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py index 94608b5d..c6274dfb 100644 --- a/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py +++ b/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py @@ -25,7 +25,6 @@ from proto.marshal.rules.dates import DurationRule, TimestampRule from google import auth -from google.api import monitored_resource_pb2 as ga_monitored_resource # type: ignore from google.api import monitored_resource_pb2 as monitored_resource # type: ignore from google.api_core import client_options from google.api_core import exceptions @@ -104,12 +103,12 @@ def test_uptime_check_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 == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_uptime_check_service_client_get_transport_class(): @@ -470,7 +469,7 @@ def test_list_uptime_check_configs( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime_service.ListUptimeCheckConfigsResponse( @@ -486,6 +485,7 @@ def test_list_uptime_check_configs( assert args[0] == uptime_service.ListUptimeCheckConfigsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListUptimeCheckConfigsPager) assert response.next_page_token == "next_page_token_value" @@ -498,18 +498,21 @@ def test_list_uptime_check_configs_from_dict(): @pytest.mark.asyncio -async def test_list_uptime_check_configs_async(transport: str = "grpc_asyncio"): +async def test_list_uptime_check_configs_async( + transport: str = "grpc_asyncio", + request_type=uptime_service.ListUptimeCheckConfigsRequest, +): client = UptimeCheckServiceAsyncClient( 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 = uptime_service.ListUptimeCheckConfigsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -524,7 +527,7 @@ async def test_list_uptime_check_configs_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == uptime_service.ListUptimeCheckConfigsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListUptimeCheckConfigsAsyncPager) @@ -534,6 +537,11 @@ async def test_list_uptime_check_configs_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_uptime_check_configs_async_from_dict(): + await test_list_uptime_check_configs_async(request_type=dict) + + def test_list_uptime_check_configs_field_headers(): client = UptimeCheckServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -544,7 +552,7 @@ def test_list_uptime_check_configs_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: call.return_value = uptime_service.ListUptimeCheckConfigsResponse() @@ -573,7 +581,7 @@ async def test_list_uptime_check_configs_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( uptime_service.ListUptimeCheckConfigsResponse() @@ -596,7 +604,7 @@ def test_list_uptime_check_configs_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime_service.ListUptimeCheckConfigsResponse() @@ -632,7 +640,7 @@ async def test_list_uptime_check_configs_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime_service.ListUptimeCheckConfigsResponse() @@ -671,7 +679,7 @@ def test_list_uptime_check_configs_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -717,7 +725,7 @@ def test_list_uptime_check_configs_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_configs), "__call__" + type(client.transport.list_uptime_check_configs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -757,7 +765,7 @@ async def test_list_uptime_check_configs_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_configs), + type(client.transport.list_uptime_check_configs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -804,7 +812,7 @@ async def test_list_uptime_check_configs_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_configs), + type(client.transport.list_uptime_check_configs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -853,7 +861,7 @@ def test_get_uptime_check_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_uptime_check_config), "__call__" + type(client.transport.get_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig( @@ -876,6 +884,7 @@ def test_get_uptime_check_config( assert args[0] == uptime_service.GetUptimeCheckConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, uptime.UptimeCheckConfig) assert response.name == "name_value" @@ -892,18 +901,21 @@ def test_get_uptime_check_config_from_dict(): @pytest.mark.asyncio -async def test_get_uptime_check_config_async(transport: str = "grpc_asyncio"): +async def test_get_uptime_check_config_async( + transport: str = "grpc_asyncio", + request_type=uptime_service.GetUptimeCheckConfigRequest, +): client = UptimeCheckServiceAsyncClient( 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 = uptime_service.GetUptimeCheckConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_uptime_check_config), "__call__" + type(client.transport.get_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -921,7 +933,7 @@ async def test_get_uptime_check_config_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == uptime_service.GetUptimeCheckConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, uptime.UptimeCheckConfig) @@ -935,6 +947,11 @@ async def test_get_uptime_check_config_async(transport: str = "grpc_asyncio"): assert response.is_internal is True +@pytest.mark.asyncio +async def test_get_uptime_check_config_async_from_dict(): + await test_get_uptime_check_config_async(request_type=dict) + + def test_get_uptime_check_config_field_headers(): client = UptimeCheckServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -945,7 +962,7 @@ def test_get_uptime_check_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_uptime_check_config), "__call__" + type(client.transport.get_uptime_check_config), "__call__" ) as call: call.return_value = uptime.UptimeCheckConfig() @@ -974,7 +991,7 @@ async def test_get_uptime_check_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_uptime_check_config), "__call__" + type(client.transport.get_uptime_check_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( uptime.UptimeCheckConfig() @@ -997,7 +1014,7 @@ def test_get_uptime_check_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_uptime_check_config), "__call__" + type(client.transport.get_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig() @@ -1033,7 +1050,7 @@ async def test_get_uptime_check_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_uptime_check_config), "__call__" + type(client.transport.get_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig() @@ -1080,7 +1097,7 @@ def test_create_uptime_check_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_uptime_check_config), "__call__" + type(client.transport.create_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig( @@ -1103,6 +1120,7 @@ def test_create_uptime_check_config( assert args[0] == uptime_service.CreateUptimeCheckConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, uptime.UptimeCheckConfig) assert response.name == "name_value" @@ -1119,18 +1137,21 @@ def test_create_uptime_check_config_from_dict(): @pytest.mark.asyncio -async def test_create_uptime_check_config_async(transport: str = "grpc_asyncio"): +async def test_create_uptime_check_config_async( + transport: str = "grpc_asyncio", + request_type=uptime_service.CreateUptimeCheckConfigRequest, +): client = UptimeCheckServiceAsyncClient( 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 = uptime_service.CreateUptimeCheckConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_uptime_check_config), "__call__" + type(client.transport.create_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1148,7 +1169,7 @@ async def test_create_uptime_check_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == uptime_service.CreateUptimeCheckConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, uptime.UptimeCheckConfig) @@ -1162,6 +1183,11 @@ async def test_create_uptime_check_config_async(transport: str = "grpc_asyncio") assert response.is_internal is True +@pytest.mark.asyncio +async def test_create_uptime_check_config_async_from_dict(): + await test_create_uptime_check_config_async(request_type=dict) + + def test_create_uptime_check_config_field_headers(): client = UptimeCheckServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1172,7 +1198,7 @@ def test_create_uptime_check_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_uptime_check_config), "__call__" + type(client.transport.create_uptime_check_config), "__call__" ) as call: call.return_value = uptime.UptimeCheckConfig() @@ -1201,7 +1227,7 @@ async def test_create_uptime_check_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_uptime_check_config), "__call__" + type(client.transport.create_uptime_check_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( uptime.UptimeCheckConfig() @@ -1224,7 +1250,7 @@ def test_create_uptime_check_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_uptime_check_config), "__call__" + type(client.transport.create_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig() @@ -1269,7 +1295,7 @@ async def test_create_uptime_check_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_uptime_check_config), "__call__" + type(client.transport.create_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig() @@ -1325,7 +1351,7 @@ def test_update_uptime_check_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_uptime_check_config), "__call__" + type(client.transport.update_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig( @@ -1348,6 +1374,7 @@ def test_update_uptime_check_config( assert args[0] == uptime_service.UpdateUptimeCheckConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, uptime.UptimeCheckConfig) assert response.name == "name_value" @@ -1364,18 +1391,21 @@ def test_update_uptime_check_config_from_dict(): @pytest.mark.asyncio -async def test_update_uptime_check_config_async(transport: str = "grpc_asyncio"): +async def test_update_uptime_check_config_async( + transport: str = "grpc_asyncio", + request_type=uptime_service.UpdateUptimeCheckConfigRequest, +): client = UptimeCheckServiceAsyncClient( 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 = uptime_service.UpdateUptimeCheckConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_uptime_check_config), "__call__" + type(client.transport.update_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1393,7 +1423,7 @@ async def test_update_uptime_check_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == uptime_service.UpdateUptimeCheckConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, uptime.UptimeCheckConfig) @@ -1407,6 +1437,11 @@ async def test_update_uptime_check_config_async(transport: str = "grpc_asyncio") assert response.is_internal is True +@pytest.mark.asyncio +async def test_update_uptime_check_config_async_from_dict(): + await test_update_uptime_check_config_async(request_type=dict) + + def test_update_uptime_check_config_field_headers(): client = UptimeCheckServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1417,7 +1452,7 @@ def test_update_uptime_check_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_uptime_check_config), "__call__" + type(client.transport.update_uptime_check_config), "__call__" ) as call: call.return_value = uptime.UptimeCheckConfig() @@ -1449,7 +1484,7 @@ async def test_update_uptime_check_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_uptime_check_config), "__call__" + type(client.transport.update_uptime_check_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( uptime.UptimeCheckConfig() @@ -1475,7 +1510,7 @@ def test_update_uptime_check_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_uptime_check_config), "__call__" + type(client.transport.update_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig() @@ -1516,7 +1551,7 @@ async def test_update_uptime_check_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_uptime_check_config), "__call__" + type(client.transport.update_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime.UptimeCheckConfig() @@ -1568,7 +1603,7 @@ def test_delete_uptime_check_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_uptime_check_config), "__call__" + type(client.transport.delete_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1590,18 +1625,21 @@ def test_delete_uptime_check_config_from_dict(): @pytest.mark.asyncio -async def test_delete_uptime_check_config_async(transport: str = "grpc_asyncio"): +async def test_delete_uptime_check_config_async( + transport: str = "grpc_asyncio", + request_type=uptime_service.DeleteUptimeCheckConfigRequest, +): client = UptimeCheckServiceAsyncClient( 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 = uptime_service.DeleteUptimeCheckConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_uptime_check_config), "__call__" + type(client.transport.delete_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1612,12 +1650,17 @@ async def test_delete_uptime_check_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == uptime_service.DeleteUptimeCheckConfigRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_uptime_check_config_async_from_dict(): + await test_delete_uptime_check_config_async(request_type=dict) + + def test_delete_uptime_check_config_field_headers(): client = UptimeCheckServiceClient(credentials=credentials.AnonymousCredentials(),) @@ -1628,7 +1671,7 @@ def test_delete_uptime_check_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_uptime_check_config), "__call__" + type(client.transport.delete_uptime_check_config), "__call__" ) as call: call.return_value = None @@ -1657,7 +1700,7 @@ async def test_delete_uptime_check_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_uptime_check_config), "__call__" + type(client.transport.delete_uptime_check_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1678,7 +1721,7 @@ def test_delete_uptime_check_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_uptime_check_config), "__call__" + type(client.transport.delete_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1714,7 +1757,7 @@ async def test_delete_uptime_check_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_uptime_check_config), "__call__" + type(client.transport.delete_uptime_check_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1759,7 +1802,7 @@ def test_list_uptime_check_ips( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_ips), "__call__" + type(client.transport.list_uptime_check_ips), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = uptime_service.ListUptimeCheckIpsResponse( @@ -1775,6 +1818,7 @@ def test_list_uptime_check_ips( assert args[0] == uptime_service.ListUptimeCheckIpsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListUptimeCheckIpsPager) assert response.next_page_token == "next_page_token_value" @@ -1785,18 +1829,21 @@ def test_list_uptime_check_ips_from_dict(): @pytest.mark.asyncio -async def test_list_uptime_check_ips_async(transport: str = "grpc_asyncio"): +async def test_list_uptime_check_ips_async( + transport: str = "grpc_asyncio", + request_type=uptime_service.ListUptimeCheckIpsRequest, +): client = UptimeCheckServiceAsyncClient( 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 = uptime_service.ListUptimeCheckIpsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_ips), "__call__" + type(client.transport.list_uptime_check_ips), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1811,7 +1858,7 @@ async def test_list_uptime_check_ips_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == uptime_service.ListUptimeCheckIpsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListUptimeCheckIpsAsyncPager) @@ -1819,12 +1866,17 @@ async def test_list_uptime_check_ips_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_uptime_check_ips_async_from_dict(): + await test_list_uptime_check_ips_async(request_type=dict) + + def test_list_uptime_check_ips_pager(): client = UptimeCheckServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_ips), "__call__" + type(client.transport.list_uptime_check_ips), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1863,7 +1915,7 @@ def test_list_uptime_check_ips_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_uptime_check_ips), "__call__" + type(client.transport.list_uptime_check_ips), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1899,7 +1951,7 @@ async def test_list_uptime_check_ips_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_ips), + type(client.transport.list_uptime_check_ips), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -1942,7 +1994,7 @@ async def test_list_uptime_check_ips_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_uptime_check_ips), + type(client.transport.list_uptime_check_ips), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2010,7 +2062,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = UptimeCheckServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2046,7 +2098,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = UptimeCheckServiceClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.UptimeCheckServiceGrpcTransport,) + assert isinstance(client.transport, transports.UptimeCheckServiceGrpcTransport,) def test_uptime_check_service_base_transport_error(): @@ -2157,7 +2209,7 @@ def test_uptime_check_service_host_no_port(): api_endpoint="monitoring.googleapis.com" ), ) - assert client._transport._host == "monitoring.googleapis.com:443" + assert client.transport._host == "monitoring.googleapis.com:443" def test_uptime_check_service_host_with_port(): @@ -2167,7 +2219,7 @@ def test_uptime_check_service_host_with_port(): api_endpoint="monitoring.googleapis.com:8000" ), ) - assert client._transport._host == "monitoring.googleapis.com:8000" + assert client.transport._host == "monitoring.googleapis.com:8000" def test_uptime_check_service_grpc_transport_channel(): @@ -2179,6 +2231,7 @@ def test_uptime_check_service_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_uptime_check_service_grpc_asyncio_transport_channel(): @@ -2190,6 +2243,7 @@ def test_uptime_check_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( @@ -2239,8 +2293,13 @@ def test_uptime_check_service_transport_channel_mtls_with_client_cert_source( ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2283,6 +2342,10 @@ def test_uptime_check_service_transport_channel_mtls_with_adc(transport_class): ), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel @@ -2312,81 +2375,81 @@ def test_parse_uptime_check_config_path(): assert expected == actual -def test_common_project_path(): - project = "oyster" +def test_common_billing_account_path(): + billing_account = "oyster" - expected = "projects/{project}".format(project=project,) - actual = UptimeCheckServiceClient.common_project_path(project) + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = UptimeCheckServiceClient.common_billing_account_path(billing_account) assert expected == actual -def test_parse_common_project_path(): +def test_parse_common_billing_account_path(): expected = { - "project": "nudibranch", + "billing_account": "nudibranch", } - path = UptimeCheckServiceClient.common_project_path(**expected) + path = UptimeCheckServiceClient.common_billing_account_path(**expected) # Check that the path construction is reversible. - actual = UptimeCheckServiceClient.parse_common_project_path(path) + actual = UptimeCheckServiceClient.parse_common_billing_account_path(path) assert expected == actual -def test_common_organization_path(): - organization = "cuttlefish" +def test_common_folder_path(): + folder = "cuttlefish" - expected = "organizations/{organization}".format(organization=organization,) - actual = UptimeCheckServiceClient.common_organization_path(organization) + expected = "folders/{folder}".format(folder=folder,) + actual = UptimeCheckServiceClient.common_folder_path(folder) assert expected == actual -def test_parse_common_organization_path(): +def test_parse_common_folder_path(): expected = { - "organization": "mussel", + "folder": "mussel", } - path = UptimeCheckServiceClient.common_organization_path(**expected) + path = UptimeCheckServiceClient.common_folder_path(**expected) # Check that the path construction is reversible. - actual = UptimeCheckServiceClient.parse_common_organization_path(path) + actual = UptimeCheckServiceClient.parse_common_folder_path(path) assert expected == actual -def test_common_folder_path(): - folder = "winkle" +def test_common_organization_path(): + organization = "winkle" - expected = "folders/{folder}".format(folder=folder,) - actual = UptimeCheckServiceClient.common_folder_path(folder) + expected = "organizations/{organization}".format(organization=organization,) + actual = UptimeCheckServiceClient.common_organization_path(organization) assert expected == actual -def test_parse_common_folder_path(): +def test_parse_common_organization_path(): expected = { - "folder": "nautilus", + "organization": "nautilus", } - path = UptimeCheckServiceClient.common_folder_path(**expected) + path = UptimeCheckServiceClient.common_organization_path(**expected) # Check that the path construction is reversible. - actual = UptimeCheckServiceClient.parse_common_folder_path(path) + actual = UptimeCheckServiceClient.parse_common_organization_path(path) assert expected == actual -def test_common_billing_account_path(): - billing_account = "scallop" +def test_common_project_path(): + project = "scallop" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = UptimeCheckServiceClient.common_billing_account_path(billing_account) + expected = "projects/{project}".format(project=project,) + actual = UptimeCheckServiceClient.common_project_path(project) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_common_project_path(): expected = { - "billing_account": "abalone", + "project": "abalone", } - path = UptimeCheckServiceClient.common_billing_account_path(**expected) + path = UptimeCheckServiceClient.common_project_path(**expected) # Check that the path construction is reversible. - actual = UptimeCheckServiceClient.parse_common_billing_account_path(path) + actual = UptimeCheckServiceClient.parse_common_project_path(path) assert expected == actual