コード例 #1
0
    def test_list_session_entity_types(self):
        # Setup Expected Response
        next_page_token = ""
        session_entity_types_element = {}
        session_entity_types = [session_entity_types_element]
        expected_response = {
            "next_page_token": next_page_token,
            "session_entity_types": session_entity_types,
        }
        expected_response = session_entity_type_pb2.ListSessionEntityTypesResponse(
            **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 = dialogflow_v2beta1.SessionEntityTypesClient()

        # Setup Request
        parent = client.session_path("[PROJECT]", "[SESSION]")

        paged_list_response = client.list_session_entity_types(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.session_entity_types[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = session_entity_type_pb2.ListSessionEntityTypesRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_list_session_entity_types(self):
        # Setup Expected Response
        next_page_token = ''
        session_entity_types_element = {}
        session_entity_types = [session_entity_types_element]
        expected_response = {
            'next_page_token': next_page_token,
            'session_entity_types': session_entity_types
        }
        expected_response = session_entity_type_pb2.ListSessionEntityTypesResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = dialogflow_v2beta1.SessionEntityTypesClient(channel=channel)

        # Setup Request
        parent = client.session_path('[PROJECT]', '[SESSION]')

        paged_list_response = client.list_session_entity_types(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.session_entity_types[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = session_entity_type_pb2.ListSessionEntityTypesRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #3
0
    def list_session_entity_types(
        self,
        parent,
        page_size=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Returns the list of all session entity types in the specified session.

        This method doesn't work with Google Assistant integration.
        Contact Dialogflow support if you need to use session entities
        with Google Assistant integration.

        Example:
            >>> import dialogflow_v2beta1
            >>>
            >>> client = dialogflow_v2beta1.SessionEntityTypesClient()
            >>>
            >>> parent = client.session_path('[PROJECT]', '[SESSION]')
            >>>
            >>> # Iterate over all results
            >>> for element in client.list_session_entity_types(parent):
            ...     # process element
            ...     pass
            >>>
            >>>
            >>> # Alternatively:
            >>>
            >>> # Iterate over results one page at a time
            >>> for page in client.list_session_entity_types(parent).pages:
            ...     for element in page:
            ...         # process element
            ...         pass

        Args:
            parent (str): Required. The session to list all session entity types from. Format:
                ``projects/<Project ID>/agent/sessions/<Session ID>`` or
                ``projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/ sessions/<Session ID>``.
                If ``Environment ID`` is not specified, we assume default 'draft'
                environment. If ``User ID`` is not specified, we assume default '-'
                user.
            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
                be retried using a default configuration.
            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.api_core.page_iterator.PageIterator` instance.
            An iterable of :class:`~google.cloud.dialogflow_v2beta1.types.SessionEntityType` instances.
            You can also iterate over the pages of the response
            using its `pages` property.

        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.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "list_session_entity_types" not in self._inner_api_calls:
            self._inner_api_calls[
                "list_session_entity_types"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.list_session_entity_types,
                    default_retry=self.
                    _method_configs["ListSessionEntityTypes"].retry,
                    default_timeout=self.
                    _method_configs["ListSessionEntityTypes"].timeout,
                    client_info=self._client_info,
                )

        request = session_entity_type_pb2.ListSessionEntityTypesRequest(
            parent=parent, page_size=page_size)
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("parent", parent)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header)
            metadata.append(routing_metadata)

        iterator = google.api_core.page_iterator.GRPCIterator(
            client=None,
            method=functools.partial(
                self._inner_api_calls["list_session_entity_types"],
                retry=retry,
                timeout=timeout,
                metadata=metadata,
            ),
            request=request,
            items_field="session_entity_types",
            request_token_field="page_token",
            response_token_field="next_page_token",
        )
        return iterator
コード例 #4
0
    def list_session_entity_types(
            self,
            parent,
            page_size=None,
            retry=google.api_core.gapic_v1.method.DEFAULT,
            timeout=google.api_core.gapic_v1.method.DEFAULT,
            metadata=None):
        """
        Returns the list of all session entity types in the specified session.

        Example:
            >>> import dialogflow_v2beta1
            >>>
            >>> client = dialogflow_v2beta1.SessionEntityTypesClient()
            >>>
            >>> parent = client.session_path('[PROJECT]', '[SESSION]')
            >>>
            >>>
            >>> # Iterate over all results
            >>> for element in client.list_session_entity_types(parent):
            ...     # process element
            ...     pass
            >>>
            >>> # Or iterate over results one page at a time
            >>> for page in client.list_session_entity_types(parent, options=CallOptions(page_token=INITIAL_PAGE)):
            ...     for element in page:
            ...         # process element
            ...         pass

        Args:
            parent (str): Required. The session to list all session entity types from.
                Format: ``projects/<Project ID>/agent/sessions/<Session ID>`` or
                ``projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/
                sessions/<Session ID>``.
                Note: Environments and users are under construction and will be available
                soon. If <Environment ID> is not specified, we assume default 'draft'
                environment. If <User ID> is not specified, we assume default '-' user.
            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:`~dialogflow_v2beta1.types.SessionEntityType` 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)
        request = session_entity_type_pb2.ListSessionEntityTypesRequest(
            parent=parent,
            page_size=page_size,
        )
        iterator = google.api_core.page_iterator.GRPCIterator(
            client=None,
            method=functools.partial(self._list_session_entity_types,
                                     retry=retry,
                                     timeout=timeout,
                                     metadata=metadata),
            request=request,
            items_field='session_entity_types',
            request_token_field='page_token',
            response_token_field='next_page_token',
        )
        return iterator