def test_list_notification_channels(self): # Setup Expected Response next_page_token = '' notification_channels_element = {} notification_channels = [notification_channels_element] expected_response = { 'next_page_token': next_page_token, 'notification_channels': notification_channels } expected_response = notification_service_pb2.ListNotificationChannelsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = monitoring_v3.NotificationChannelServiceClient( channel=channel) # Setup Request name = client.project_path('[PROJECT]') paged_list_response = client.list_notification_channels(name) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.notification_channels[0] == resources[0] assert len(channel.requests) == 1 expected_request = notification_service_pb2.ListNotificationChannelsRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_notification_channels(self): # Setup Expected Response next_page_token = "" notification_channels_element = {} notification_channels = [notification_channels_element] expected_response = { "next_page_token": next_page_token, "notification_channels": notification_channels, } expected_response = notification_service_pb2.ListNotificationChannelsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = monitoring_v3.NotificationChannelServiceClient() # Setup Request name = client.project_path("[PROJECT]") paged_list_response = client.list_notification_channels(name) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.notification_channels[0] == resources[0] assert len(channel.requests) == 1 expected_request = notification_service_pb2.ListNotificationChannelsRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def list_notification_channels( self, name, filter_=None, order_by=None, page_size=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None): """ Lists the notification channels that have been created for the project. Example: >>> from google.cloud import monitoring_v3 >>> >>> client = monitoring_v3.NotificationChannelServiceClient() >>> >>> name = client.project_path('[PROJECT]') >>> >>> # Iterate over all results >>> for element in client.list_notification_channels(name): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_notification_channels(name, options=CallOptions(page_token=INITIAL_PAGE)): ... for element in page: ... # process element ... pass Args: name (str): The project on which to execute the request. The format is ``projects/[PROJECT_ID]``. That is, this names the container in which to look for the notification channels; it does not name a specific channel. To query a specific channel by REST resource name, use the ````GetNotificationChannel```` operation. filter_ (str): If provided, this field specifies the criteria that must be met by notification channels to be included in the response. For more details, see [sorting and filtering](/monitoring/api/v3/sorting-and-filtering). order_by (str): A comma-separated list of fields by which to sort the result. Supports the same set of fields as in ``filter``. Entries can be prefixed with a minus sign to sort in descending rather than ascending order. For more details, see [sorting and filtering](/monitoring/api/v3/sorting-and-filtering). page_size (int): The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will not be retried. timeout (Optional[float]): The amount of time, in seconds, to wait for the request to complete. Note that if ``retry`` is specified, the timeout applies to each individual attempt. metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata that is provided to the method. Returns: A :class:`~google.gax.PageIterator` instance. By default, this is an iterable of :class:`~google.cloud.monitoring_v3.types.NotificationChannel` instances. This object can also be configured to iterate over the pages of the response through the `options` parameter. Raises: google.api_core.exceptions.GoogleAPICallError: If the request failed for any reason. google.api_core.exceptions.RetryError: If the request failed due to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ if metadata is None: metadata = [] metadata = list(metadata) if 'list_notification_channels' not in self._inner_api_calls: self._inner_api_calls[ 'list_notification_channels'] = google.api_core.gapic_v1.method.wrap_method( self._notification_channel_service_stub. ListNotificationChannels, default_retry=self. _method_configs['ListNotificationChannels'].retry, default_timeout=self. _method_configs['ListNotificationChannels'].timeout, client_info=self._client_info, ) request = notification_service_pb2.ListNotificationChannelsRequest( name=name, filter=filter_, order_by=order_by, page_size=page_size, ) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls['list_notification_channels'], retry=retry, timeout=timeout, metadata=metadata), request=request, items_field='notification_channels', request_token_field='page_token', response_token_field='next_page_token', ) return iterator