def test_create_notification_channel(self): # Setup Expected Response type_ = 'type3575610' name_2 = 'name2-1052831874' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'type': type_, 'name': name_2, 'display_name': display_name, 'description': description } expected_response = notification_pb2.NotificationChannel( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = monitoring_v3.NotificationChannelServiceClient( channel=channel) # Setup Request name = client.project_path('[PROJECT]') notification_channel = {} response = client.create_notification_channel(name, notification_channel) assert expected_response == response assert len(channel.requests) == 1 expected_request = notification_service_pb2.CreateNotificationChannelRequest( name=name, notification_channel=notification_channel) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_notification_channel(self): # Setup Expected Response type_ = "type3575610" name_2 = "name2-1052831874" display_name = "displayName1615086568" description = "description-1724546052" expected_response = { "type": type_, "name": name_2, "display_name": display_name, "description": description, } expected_response = notification_pb2.NotificationChannel( **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]") notification_channel = {} response = client.create_notification_channel(name, notification_channel) assert expected_response == response assert len(channel.requests) == 1 expected_request = notification_service_pb2.CreateNotificationChannelRequest( name=name, notification_channel=notification_channel) actual_request = channel.requests[0][1] assert expected_request == actual_request
def create_notification_channel( self, name, notification_channel, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None): """ Creates a new notification channel, representing a single notification endpoint such as an email address, SMS number, or pagerduty service. Example: >>> from google.cloud import monitoring_v3 >>> >>> client = monitoring_v3.NotificationChannelServiceClient() >>> >>> name = client.project_path('[PROJECT]') >>> >>> # TODO: Initialize ``notification_channel``: >>> notification_channel = {} >>> >>> response = client.create_notification_channel(name, notification_channel) Args: name (str): The project on which to execute the request. The format is: :: projects/[PROJECT_ID] Note that this names the container into which the channel will be written. This does not name the newly created channel. The resulting channel's name will have a normalized version of this field as a prefix, but will add ``/notificationChannels/[CHANNEL_ID]`` to identify the channel. notification_channel (Union[dict, ~google.cloud.monitoring_v3.types.NotificationChannel]): The definition of the ``NotificationChannel`` to create. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.monitoring_v3.types.NotificationChannel` 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.cloud.monitoring_v3.types.NotificationChannel` instance. 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 'create_notification_channel' not in self._inner_api_calls: self._inner_api_calls[ 'create_notification_channel'] = google.api_core.gapic_v1.method.wrap_method( self._notification_channel_service_stub. CreateNotificationChannel, default_retry=self. _method_configs['CreateNotificationChannel'].retry, default_timeout=self. _method_configs['CreateNotificationChannel'].timeout, client_info=self._client_info, ) request = notification_service_pb2.CreateNotificationChannelRequest( name=name, notification_channel=notification_channel, ) return self._inner_api_calls['create_notification_channel']( request, retry=retry, timeout=timeout, metadata=metadata)