diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx/gapic_version.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx/gapic_version.py index c9ad683ef7e5..20a9cd975b02 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx/gapic_version.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.43.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/gapic_version.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/gapic_version.py index c9ad683ef7e5..20a9cd975b02 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/gapic_version.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.43.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/__init__.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/__init__.py index 0e5625bab99f..3397470c48ec 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/__init__.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/__init__.py @@ -145,22 +145,13 @@ UpdateEnvironmentRequest, ) from .types.example import ( - Action, - AgentUtterance, CreateExampleRequest, DeleteExampleRequest, Example, - FlowInvocation, GetExampleRequest, ListExamplesRequest, ListExamplesResponse, - OutputState, - PlaybookInput, - PlaybookInvocation, - PlaybookOutput, - ToolUse, UpdateExampleRequest, - UserUtterance, ) from .types.experiment import ( CreateExperimentRequest, @@ -240,21 +231,33 @@ TransitionRoute, UpdatePageRequest, ) -from .types.parameter_definition import ParameterDefinition +from .types.parameter_definition import ( + DataType, + InlineSchema, + ParameterDefinition, + TypeSchema, +) from .types.playbook import ( CreatePlaybookRequest, CreatePlaybookVersionRequest, DeletePlaybookRequest, DeletePlaybookVersionRequest, + ExportPlaybookRequest, + ExportPlaybookResponse, GetPlaybookRequest, GetPlaybookVersionRequest, Handler, + ImportPlaybookRequest, + ImportPlaybookResponse, ListPlaybooksRequest, ListPlaybooksResponse, ListPlaybookVersionsRequest, ListPlaybookVersionsResponse, Playbook, + PlaybookImportStrategy, PlaybookVersion, + RestorePlaybookVersionRequest, + RestorePlaybookVersionResponse, UpdatePlaybookRequest, ) from .types.response_message import ResponseMessage @@ -363,6 +366,26 @@ UpdateToolRequest, ) from .types.tool_call import ToolCall, ToolCallResult +from .types.trace import ( + Action, + AgentUtterance, + Event, + ExceptionDetail, + FlowInvocation, + FlowTransition, + LlmCall, + NamedMetric, + OutputState, + PlaybookInput, + PlaybookInvocation, + PlaybookOutput, + PlaybookTransition, + RetrievalStrategy, + Span, + Status, + ToolUse, + UserUtterance, +) from .types.transition_route_group import ( CreateTransitionRouteGroupRequest, DeleteTransitionRouteGroupRequest, @@ -474,6 +497,7 @@ "DataStoreConnection", "DataStoreConnectionSignals", "DataStoreType", + "DataType", "DeleteAgentRequest", "DeleteConversationRequest", "DeleteEntityTypeRequest", @@ -506,10 +530,12 @@ "EntityTypesClient", "Environment", "EnvironmentsClient", + "Event", "EventHandler", "EventInput", "Example", "ExamplesClient", + "ExceptionDetail", "Experiment", "ExperimentsClient", "ExportAgentRequest", @@ -522,6 +548,8 @@ "ExportIntentsMetadata", "ExportIntentsRequest", "ExportIntentsResponse", + "ExportPlaybookRequest", + "ExportPlaybookResponse", "ExportTestCasesMetadata", "ExportTestCasesRequest", "ExportTestCasesResponse", @@ -532,6 +560,7 @@ "Flow", "FlowImportStrategy", "FlowInvocation", + "FlowTransition", "FlowValidationResult", "FlowsClient", "Form", @@ -578,11 +607,14 @@ "ImportIntentsMetadata", "ImportIntentsRequest", "ImportIntentsResponse", + "ImportPlaybookRequest", + "ImportPlaybookResponse", "ImportStrategy", "ImportTestCasesMetadata", "ImportTestCasesRequest", "ImportTestCasesResponse", "InlineDestination", + "InlineSchema", "InlineSource", "InputAudioConfig", "Intent", @@ -640,6 +672,7 @@ "ListVersionsResponse", "ListWebhooksRequest", "ListWebhooksResponse", + "LlmCall", "LlmModelSettings", "LoadVersionRequest", "LookupEnvironmentHistoryRequest", @@ -647,6 +680,7 @@ "Match", "MatchIntentRequest", "MatchIntentResponse", + "NamedMetric", "NluSettings", "OutputAudioConfig", "OutputAudioEncoding", @@ -657,9 +691,11 @@ "ParameterDefinition", "Phrase", "Playbook", + "PlaybookImportStrategy", "PlaybookInput", "PlaybookInvocation", "PlaybookOutput", + "PlaybookTransition", "PlaybookVersion", "PlaybooksClient", "QueryInput", @@ -668,8 +704,11 @@ "ResourceName", "ResponseMessage", "RestoreAgentRequest", + "RestorePlaybookVersionRequest", + "RestorePlaybookVersionResponse", "RestoreToolVersionRequest", "RestoreToolVersionResponse", + "RetrievalStrategy", "RolloutConfig", "RolloutState", "RunContinuousTestMetadata", @@ -687,11 +726,13 @@ "SessionEntityTypesClient", "SessionInfo", "SessionsClient", + "Span", "SpeechModelVariant", "SpeechToTextSettings", "SpeechWordInfo", "SsmlVoiceGender", "StartExperimentRequest", + "Status", "StopExperimentRequest", "StreamingDetectIntentRequest", "StreamingDetectIntentResponse", @@ -720,6 +761,7 @@ "TransitionRouteGroup", "TransitionRouteGroupCoverage", "TransitionRouteGroupsClient", + "TypeSchema", "UpdateAgentRequest", "UpdateEntityTypeRequest", "UpdateEnvironmentRequest", diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json index f5e7d8a6aa5f..f49e50d3be78 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json @@ -1353,6 +1353,11 @@ "delete_playbook_version" ] }, + "ExportPlaybook": { + "methods": [ + "export_playbook" + ] + }, "GetPlaybook": { "methods": [ "get_playbook" @@ -1363,6 +1368,11 @@ "get_playbook_version" ] }, + "ImportPlaybook": { + "methods": [ + "import_playbook" + ] + }, "ListPlaybookVersions": { "methods": [ "list_playbook_versions" @@ -1373,6 +1383,11 @@ "list_playbooks" ] }, + "RestorePlaybookVersion": { + "methods": [ + "restore_playbook_version" + ] + }, "UpdatePlaybook": { "methods": [ "update_playbook" @@ -1403,6 +1418,11 @@ "delete_playbook_version" ] }, + "ExportPlaybook": { + "methods": [ + "export_playbook" + ] + }, "GetPlaybook": { "methods": [ "get_playbook" @@ -1413,6 +1433,11 @@ "get_playbook_version" ] }, + "ImportPlaybook": { + "methods": [ + "import_playbook" + ] + }, "ListPlaybookVersions": { "methods": [ "list_playbook_versions" @@ -1423,6 +1448,11 @@ "list_playbooks" ] }, + "RestorePlaybookVersion": { + "methods": [ + "restore_playbook_version" + ] + }, "UpdatePlaybook": { "methods": [ "update_playbook" @@ -1453,6 +1483,11 @@ "delete_playbook_version" ] }, + "ExportPlaybook": { + "methods": [ + "export_playbook" + ] + }, "GetPlaybook": { "methods": [ "get_playbook" @@ -1463,6 +1498,11 @@ "get_playbook_version" ] }, + "ImportPlaybook": { + "methods": [ + "import_playbook" + ] + }, "ListPlaybookVersions": { "methods": [ "list_playbook_versions" @@ -1473,6 +1513,11 @@ "list_playbooks" ] }, + "RestorePlaybookVersion": { + "methods": [ + "restore_playbook_version" + ] + }, "UpdatePlaybook": { "methods": [ "update_playbook" diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_version.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_version.py index c9ad683ef7e5..20a9cd975b02 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_version.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.43.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py index 56a917854712..5e77c2ce462a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py @@ -104,12 +104,18 @@ class ConversationHistoryAsyncClient: parse_example_path = staticmethod(ConversationHistoryClient.parse_example_path) flow_path = staticmethod(ConversationHistoryClient.flow_path) parse_flow_path = staticmethod(ConversationHistoryClient.parse_flow_path) + generator_path = staticmethod(ConversationHistoryClient.generator_path) + parse_generator_path = staticmethod(ConversationHistoryClient.parse_generator_path) intent_path = staticmethod(ConversationHistoryClient.intent_path) parse_intent_path = staticmethod(ConversationHistoryClient.parse_intent_path) page_path = staticmethod(ConversationHistoryClient.page_path) parse_page_path = staticmethod(ConversationHistoryClient.parse_page_path) playbook_path = staticmethod(ConversationHistoryClient.playbook_path) parse_playbook_path = staticmethod(ConversationHistoryClient.parse_playbook_path) + secret_version_path = staticmethod(ConversationHistoryClient.secret_version_path) + parse_secret_version_path = staticmethod( + ConversationHistoryClient.parse_secret_version_path + ) service_path = staticmethod(ConversationHistoryClient.service_path) parse_service_path = staticmethod(ConversationHistoryClient.parse_service_path) session_path = staticmethod(ConversationHistoryClient.session_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py index d9faa4f680ce..f378719ee715 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py @@ -351,6 +351,30 @@ def parse_flow_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def generator_path( + project: str, + location: str, + agent: str, + generator: str, + ) -> str: + """Returns a fully-qualified generator string.""" + return "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + + @staticmethod + def parse_generator_path(path: str) -> Dict[str, str]: + """Parses a generator path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/generators/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def intent_path( project: str, @@ -425,6 +449,28 @@ def parse_playbook_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def secret_version_path( + project: str, + secret: str, + version: str, + ) -> str: + """Returns a fully-qualified secret_version string.""" + return "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + + @staticmethod + def parse_secret_version_path(path: str) -> Dict[str, str]: + """Parses a secret_version path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/secrets/(?P.+?)/versions/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def service_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py index a4c3151c89e7..d0a5e73b72e3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py @@ -92,6 +92,10 @@ class EnvironmentsAsyncClient: ) environment_path = staticmethod(EnvironmentsClient.environment_path) parse_environment_path = staticmethod(EnvironmentsClient.parse_environment_path) + secret_version_path = staticmethod(EnvironmentsClient.secret_version_path) + parse_secret_version_path = staticmethod( + EnvironmentsClient.parse_secret_version_path + ) service_path = staticmethod(EnvironmentsClient.service_path) parse_service_path = staticmethod(EnvironmentsClient.parse_service_path) test_case_path = staticmethod(EnvironmentsClient.test_case_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py index d823b977dd9f..b68fba286f2a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py @@ -255,6 +255,28 @@ def parse_environment_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def secret_version_path( + project: str, + secret: str, + version: str, + ) -> str: + """Returns a fully-qualified secret_version string.""" + return "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + + @staticmethod + def parse_secret_version_path(path: str) -> Dict[str, str]: + """Parses a secret_version path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/secrets/(?P.+?)/versions/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def service_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py index 26f275e98689..a1ea192f709a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py @@ -52,6 +52,7 @@ from google.cloud.dialogflowcx_v3beta1.services.examples import pagers from google.cloud.dialogflowcx_v3beta1.types import example from google.cloud.dialogflowcx_v3beta1.types import example as gcdc_example +from google.cloud.dialogflowcx_v3beta1.types import trace from .client import ExamplesClient from .transports.base import DEFAULT_CLIENT_INFO, ExamplesTransport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py index 0a225945ba1c..b5ab128df3a2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py @@ -69,6 +69,7 @@ from google.cloud.dialogflowcx_v3beta1.services.examples import pagers from google.cloud.dialogflowcx_v3beta1.types import example from google.cloud.dialogflowcx_v3beta1.types import example as gcdc_example +from google.cloud.dialogflowcx_v3beta1.types import trace from .transports.base import DEFAULT_CLIENT_INFO, ExamplesTransport from .transports.grpc import ExamplesGrpcTransport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py index ecdd8d6f6b54..750aa3c5d0cd 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py @@ -54,10 +54,14 @@ from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.dialogflowcx_v3beta1.services.flows import pagers +from google.cloud.dialogflowcx_v3beta1.types import ( + page, + parameter_definition, + validation_message, +) from google.cloud.dialogflowcx_v3beta1.types import advanced_settings from google.cloud.dialogflowcx_v3beta1.types import flow from google.cloud.dialogflowcx_v3beta1.types import flow as gcdc_flow -from google.cloud.dialogflowcx_v3beta1.types import page, validation_message from .client import FlowsClient from .transports.base import DEFAULT_CLIENT_INFO, FlowsTransport @@ -93,6 +97,8 @@ class FlowsAsyncClient: parse_flow_validation_result_path = staticmethod( FlowsClient.parse_flow_validation_result_path ) + generator_path = staticmethod(FlowsClient.generator_path) + parse_generator_path = staticmethod(FlowsClient.parse_generator_path) intent_path = staticmethod(FlowsClient.intent_path) parse_intent_path = staticmethod(FlowsClient.parse_intent_path) page_path = staticmethod(FlowsClient.page_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py index e6b36bf25944..fc46987b2911 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py @@ -71,10 +71,14 @@ from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.dialogflowcx_v3beta1.services.flows import pagers +from google.cloud.dialogflowcx_v3beta1.types import ( + page, + parameter_definition, + validation_message, +) from google.cloud.dialogflowcx_v3beta1.types import advanced_settings from google.cloud.dialogflowcx_v3beta1.types import flow from google.cloud.dialogflowcx_v3beta1.types import flow as gcdc_flow -from google.cloud.dialogflowcx_v3beta1.types import page, validation_message from .transports.base import DEFAULT_CLIENT_INFO, FlowsTransport from .transports.grpc import FlowsGrpcTransport @@ -256,6 +260,30 @@ def parse_flow_validation_result_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def generator_path( + project: str, + location: str, + agent: str, + generator: str, + ) -> str: + """Returns a fully-qualified generator string.""" + return "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + + @staticmethod + def parse_generator_path(path: str) -> Dict[str, str]: + """Parses a generator path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/generators/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def intent_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py index 7323965496ed..0ae686e96b6a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py @@ -85,6 +85,8 @@ class PagesAsyncClient: parse_entity_type_path = staticmethod(PagesClient.parse_entity_type_path) flow_path = staticmethod(PagesClient.flow_path) parse_flow_path = staticmethod(PagesClient.parse_flow_path) + generator_path = staticmethod(PagesClient.generator_path) + parse_generator_path = staticmethod(PagesClient.parse_generator_path) intent_path = staticmethod(PagesClient.intent_path) parse_intent_path = staticmethod(PagesClient.parse_intent_path) page_path = staticmethod(PagesClient.page_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py index 038abbe90ed5..9b93b2245cbb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py @@ -250,6 +250,30 @@ def parse_flow_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def generator_path( + project: str, + location: str, + agent: str, + generator: str, + ) -> str: + """Returns a fully-qualified generator string.""" + return "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + + @staticmethod + def parse_generator_path(path: str) -> Dict[str, str]: + """Parses a generator path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/generators/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def intent_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py index dcec56fbc5d0..103e8c0c3437 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py @@ -44,9 +44,12 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.dialogflowcx_v3beta1.services.playbooks import pagers @@ -91,6 +94,8 @@ class PlaybooksAsyncClient: parse_example_path = staticmethod(PlaybooksClient.parse_example_path) flow_path = staticmethod(PlaybooksClient.flow_path) parse_flow_path = staticmethod(PlaybooksClient.parse_flow_path) + generator_path = staticmethod(PlaybooksClient.generator_path) + parse_generator_path = staticmethod(PlaybooksClient.parse_generator_path) playbook_path = staticmethod(PlaybooksClient.playbook_path) parse_playbook_path = staticmethod(PlaybooksClient.parse_playbook_path) playbook_version_path = staticmethod(PlaybooksClient.playbook_version_path) @@ -789,6 +794,211 @@ async def sample_get_playbook(): # Done; return the response. return response + async def export_playbook( + self, + request: Optional[Union[playbook.ExportPlaybookRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation_async.AsyncOperation: + r"""Exports the specified playbook to a binary file. + + Note that resources (e.g. examples, tools) that the + playbook references will also be exported. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import dialogflowcx_v3beta1 + + async def sample_export_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksAsyncClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ExportPlaybookRequest( + name="name_value", + ) + + # Make the request + operation = client.export_playbook(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.dialogflowcx_v3beta1.types.ExportPlaybookRequest, dict]]): + The request object. The request message for + [Playbooks.ExportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook]. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.dialogflowcx_v3beta1.types.ExportPlaybookResponse` The response message for + [Playbooks.ExportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook]. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, playbook.ExportPlaybookRequest): + request = playbook.ExportPlaybookRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.export_playbook + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + playbook.ExportPlaybookResponse, + metadata_type=struct_pb2.Struct, + ) + + # Done; return the response. + return response + + async def import_playbook( + self, + request: Optional[Union[playbook.ImportPlaybookRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation_async.AsyncOperation: + r"""Imports the specified playbook to the specified agent + from a binary file. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import dialogflowcx_v3beta1 + + async def sample_import_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksAsyncClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ImportPlaybookRequest( + playbook_uri="playbook_uri_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_playbook(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.dialogflowcx_v3beta1.types.ImportPlaybookRequest, dict]]): + The request object. The request message for + [Playbooks.ImportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook]. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.dialogflowcx_v3beta1.types.ImportPlaybookResponse` The response message for + [Playbooks.ImportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook]. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, playbook.ImportPlaybookRequest): + request = playbook.ImportPlaybookRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.import_playbook + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + playbook.ImportPlaybookResponse, + metadata_type=struct_pb2.Struct, + ) + + # Done; return the response. + return response + async def update_playbook( self, request: Optional[Union[gcdc_playbook.UpdatePlaybookRequest, dict]] = None, @@ -1158,6 +1368,119 @@ async def sample_get_playbook_version(): # Done; return the response. return response + async def restore_playbook_version( + self, + request: Optional[Union[playbook.RestorePlaybookVersionRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> playbook.RestorePlaybookVersionResponse: + r"""Retrieves the specified version of the Playbook and + stores it as the current playbook draft, returning the + playbook with resources updated. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import dialogflowcx_v3beta1 + + async def sample_restore_playbook_version(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksAsyncClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.RestorePlaybookVersionRequest( + name="name_value", + ) + + # Make the request + response = await client.restore_playbook_version(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionRequest, dict]]): + The request object. The request message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + name (:class:`str`): + Required. The name of the playbook version. Format: + ``projects//locations//agents//playbooks//versions/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionResponse: + The response message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + 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." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, playbook.RestorePlaybookVersionRequest): + request = playbook.RestorePlaybookVersionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.restore_playbook_version + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def list_playbook_versions( self, request: Optional[Union[playbook.ListPlaybookVersionsRequest, dict]] = None, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py index 19447d148f34..cc079642799d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py @@ -61,9 +61,12 @@ _LOGGER = std_logging.getLogger(__name__) +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.dialogflowcx_v3beta1.services.playbooks import pagers @@ -258,6 +261,30 @@ def parse_flow_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def generator_path( + project: str, + location: str, + agent: str, + generator: str, + ) -> str: + """Returns a fully-qualified generator string.""" + return "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + + @staticmethod + def parse_generator_path(path: str) -> Dict[str, str]: + """Parses a generator path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/generators/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def playbook_path( project: str, @@ -1315,6 +1342,207 @@ def sample_get_playbook(): # Done; return the response. return response + def export_playbook( + self, + request: Optional[Union[playbook.ExportPlaybookRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation.Operation: + r"""Exports the specified playbook to a binary file. + + Note that resources (e.g. examples, tools) that the + playbook references will also be exported. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import dialogflowcx_v3beta1 + + def sample_export_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ExportPlaybookRequest( + name="name_value", + ) + + # Make the request + operation = client.export_playbook(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.dialogflowcx_v3beta1.types.ExportPlaybookRequest, dict]): + The request object. The request message for + [Playbooks.ExportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.dialogflowcx_v3beta1.types.ExportPlaybookResponse` The response message for + [Playbooks.ExportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook]. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, playbook.ExportPlaybookRequest): + request = playbook.ExportPlaybookRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.export_playbook] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + playbook.ExportPlaybookResponse, + metadata_type=struct_pb2.Struct, + ) + + # Done; return the response. + return response + + def import_playbook( + self, + request: Optional[Union[playbook.ImportPlaybookRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operation.Operation: + r"""Imports the specified playbook to the specified agent + from a binary file. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import dialogflowcx_v3beta1 + + def sample_import_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ImportPlaybookRequest( + playbook_uri="playbook_uri_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_playbook(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.dialogflowcx_v3beta1.types.ImportPlaybookRequest, dict]): + The request object. The request message for + [Playbooks.ImportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.dialogflowcx_v3beta1.types.ImportPlaybookResponse` The response message for + [Playbooks.ImportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook]. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, playbook.ImportPlaybookRequest): + request = playbook.ImportPlaybookRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.import_playbook] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + playbook.ImportPlaybookResponse, + metadata_type=struct_pb2.Struct, + ) + + # Done; return the response. + return response + def update_playbook( self, request: Optional[Union[gcdc_playbook.UpdatePlaybookRequest, dict]] = None, @@ -1675,6 +1903,116 @@ def sample_get_playbook_version(): # Done; return the response. return response + def restore_playbook_version( + self, + request: Optional[Union[playbook.RestorePlaybookVersionRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> playbook.RestorePlaybookVersionResponse: + r"""Retrieves the specified version of the Playbook and + stores it as the current playbook draft, returning the + playbook with resources updated. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import dialogflowcx_v3beta1 + + def sample_restore_playbook_version(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.RestorePlaybookVersionRequest( + name="name_value", + ) + + # Make the request + response = client.restore_playbook_version(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionRequest, dict]): + The request object. The request message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + name (str): + Required. The name of the playbook version. Format: + ``projects//locations//agents//playbooks//versions/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionResponse: + The response message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + 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." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, playbook.RestorePlaybookVersionRequest): + request = playbook.RestorePlaybookVersionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.restore_playbook_version] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + def list_playbook_versions( self, request: Optional[Union[playbook.ListPlaybookVersionsRequest, dict]] = None, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py index b2dbad9a8209..20fe4c971f16 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py @@ -18,7 +18,7 @@ import google.api_core from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore @@ -160,6 +160,16 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.export_playbook: gapic_v1.method.wrap_method( + self.export_playbook, + default_timeout=None, + client_info=client_info, + ), + self.import_playbook: gapic_v1.method.wrap_method( + self.import_playbook, + default_timeout=None, + client_info=client_info, + ), self.update_playbook: gapic_v1.method.wrap_method( self.update_playbook, default_timeout=None, @@ -175,6 +185,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.restore_playbook_version: gapic_v1.method.wrap_method( + self.restore_playbook_version, + default_timeout=None, + client_info=client_info, + ), self.list_playbook_versions: gapic_v1.method.wrap_method( self.list_playbook_versions, default_timeout=None, @@ -221,6 +236,11 @@ def close(self): """ raise NotImplementedError() + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + @property def create_playbook( self, @@ -259,6 +279,24 @@ def get_playbook( ]: raise NotImplementedError() + @property + def export_playbook( + self, + ) -> Callable[ + [playbook.ExportPlaybookRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def import_playbook( + self, + ) -> Callable[ + [playbook.ImportPlaybookRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def update_playbook( self, @@ -286,6 +324,18 @@ def get_playbook_version( ]: raise NotImplementedError() + @property + def restore_playbook_version( + self, + ) -> Callable[ + [playbook.RestorePlaybookVersionRequest], + Union[ + playbook.RestorePlaybookVersionResponse, + Awaitable[playbook.RestorePlaybookVersionResponse], + ], + ]: + raise NotImplementedError() + @property def list_playbook_versions( self, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py index cec3c66e15ae..8892028625f9 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py @@ -19,7 +19,7 @@ from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, grpc_helpers +from google.api_core import gapic_v1, grpc_helpers, operations_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -199,6 +199,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -326,6 +327,22 @@ def grpc_channel(self) -> grpc.Channel: """Return the channel designed to connect to this service.""" return self._grpc_channel + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) + + # Return the client from cache. + return self._operations_client + @property def create_playbook( self, @@ -430,6 +447,62 @@ def get_playbook( ) return self._stubs["get_playbook"] + @property + def export_playbook( + self, + ) -> Callable[[playbook.ExportPlaybookRequest], operations_pb2.Operation]: + r"""Return a callable for the export playbook method over gRPC. + + Exports the specified playbook to a binary file. + + Note that resources (e.g. examples, tools) that the + playbook references will also be exported. + + Returns: + Callable[[~.ExportPlaybookRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_playbook" not in self._stubs: + self._stubs["export_playbook"] = self._logged_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Playbooks/ExportPlaybook", + request_serializer=playbook.ExportPlaybookRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["export_playbook"] + + @property + def import_playbook( + self, + ) -> Callable[[playbook.ImportPlaybookRequest], operations_pb2.Operation]: + r"""Return a callable for the import playbook method over gRPC. + + Imports the specified playbook to the specified agent + from a binary file. + + Returns: + Callable[[~.ImportPlaybookRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_playbook" not in self._stubs: + self._stubs["import_playbook"] = self._logged_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Playbooks/ImportPlaybook", + request_serializer=playbook.ImportPlaybookRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["import_playbook"] + @property def update_playbook( self, @@ -508,6 +581,37 @@ def get_playbook_version( ) return self._stubs["get_playbook_version"] + @property + def restore_playbook_version( + self, + ) -> Callable[ + [playbook.RestorePlaybookVersionRequest], + playbook.RestorePlaybookVersionResponse, + ]: + r"""Return a callable for the restore playbook version method over gRPC. + + Retrieves the specified version of the Playbook and + stores it as the current playbook draft, returning the + playbook with resources updated. + + Returns: + Callable[[~.RestorePlaybookVersionRequest], + ~.RestorePlaybookVersionResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "restore_playbook_version" not in self._stubs: + self._stubs["restore_playbook_version"] = self._logged_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Playbooks/RestorePlaybookVersion", + request_serializer=playbook.RestorePlaybookVersionRequest.serialize, + response_deserializer=playbook.RestorePlaybookVersionResponse.deserialize, + ) + return self._stubs["restore_playbook_version"] + @property def list_playbook_versions( self, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py index 7f4d3632d011..3fe85b2f6a8c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py @@ -21,7 +21,7 @@ import warnings from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1, grpc_helpers_async +from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -250,6 +250,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -334,6 +335,22 @@ def grpc_channel(self) -> aio.Channel: # Return the channel from cache. return self._grpc_channel + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self._logged_channel + ) + + # Return the client from cache. + return self._operations_client + @property def create_playbook( self, @@ -442,6 +459,66 @@ def get_playbook( ) return self._stubs["get_playbook"] + @property + def export_playbook( + self, + ) -> Callable[ + [playbook.ExportPlaybookRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the export playbook method over gRPC. + + Exports the specified playbook to a binary file. + + Note that resources (e.g. examples, tools) that the + playbook references will also be exported. + + Returns: + Callable[[~.ExportPlaybookRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_playbook" not in self._stubs: + self._stubs["export_playbook"] = self._logged_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Playbooks/ExportPlaybook", + request_serializer=playbook.ExportPlaybookRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["export_playbook"] + + @property + def import_playbook( + self, + ) -> Callable[ + [playbook.ImportPlaybookRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the import playbook method over gRPC. + + Imports the specified playbook to the specified agent + from a binary file. + + Returns: + Callable[[~.ImportPlaybookRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_playbook" not in self._stubs: + self._stubs["import_playbook"] = self._logged_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Playbooks/ImportPlaybook", + request_serializer=playbook.ImportPlaybookRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["import_playbook"] + @property def update_playbook( self, @@ -526,6 +603,37 @@ def get_playbook_version( ) return self._stubs["get_playbook_version"] + @property + def restore_playbook_version( + self, + ) -> Callable[ + [playbook.RestorePlaybookVersionRequest], + Awaitable[playbook.RestorePlaybookVersionResponse], + ]: + r"""Return a callable for the restore playbook version method over gRPC. + + Retrieves the specified version of the Playbook and + stores it as the current playbook draft, returning the + playbook with resources updated. + + Returns: + Callable[[~.RestorePlaybookVersionRequest], + Awaitable[~.RestorePlaybookVersionResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "restore_playbook_version" not in self._stubs: + self._stubs["restore_playbook_version"] = self._logged_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Playbooks/RestorePlaybookVersion", + request_serializer=playbook.RestorePlaybookVersionRequest.serialize, + response_deserializer=playbook.RestorePlaybookVersionResponse.deserialize, + ) + return self._stubs["restore_playbook_version"] + @property def list_playbook_versions( self, @@ -604,6 +712,16 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.export_playbook: self._wrap_method( + self.export_playbook, + default_timeout=None, + client_info=client_info, + ), + self.import_playbook: self._wrap_method( + self.import_playbook, + default_timeout=None, + client_info=client_info, + ), self.update_playbook: self._wrap_method( self.update_playbook, default_timeout=None, @@ -619,6 +737,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.restore_playbook_version: self._wrap_method( + self.restore_playbook_version, + default_timeout=None, + client_info=client_info, + ), self.list_playbook_versions: self._wrap_method( self.list_playbook_versions, default_timeout=None, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py index e77c78a1d9a9..7723036b6d22 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py @@ -19,8 +19,8 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore @@ -100,6 +100,14 @@ def pre_delete_playbook_version(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata + def pre_export_playbook(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_export_playbook(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_playbook(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -116,6 +124,14 @@ def post_get_playbook_version(self, response): logging.log(f"Received response: {response}") return response + def pre_import_playbook(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_import_playbook(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_playbooks(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -132,6 +148,14 @@ def post_list_playbook_versions(self, response): logging.log(f"Received response: {response}") return response + def pre_restore_playbook_version(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_restore_playbook_version(self, response): + logging.log(f"Received response: {response}") + return response + def pre_update_playbook(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -268,6 +292,52 @@ def pre_delete_playbook_version( """ return request, metadata + def pre_export_playbook( + self, + request: playbook.ExportPlaybookRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[playbook.ExportPlaybookRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for export_playbook + + Override in a subclass to manipulate the request or metadata + before they are sent to the Playbooks server. + """ + return request, metadata + + def post_export_playbook( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for export_playbook + + DEPRECATED. Please use the `post_export_playbook_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the Playbooks server but before + it is returned to user code. This `post_export_playbook` interceptor runs + before the `post_export_playbook_with_metadata` interceptor. + """ + return response + + def post_export_playbook_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for export_playbook + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the Playbooks server but before it is returned to user code. + + We recommend only using this `post_export_playbook_with_metadata` + interceptor in new development instead of the `post_export_playbook` interceptor. + When both interceptors are used, this `post_export_playbook_with_metadata` interceptor runs after the + `post_export_playbook` interceptor. The (possibly modified) response returned by + `post_export_playbook` will be passed to + `post_export_playbook_with_metadata`. + """ + return response, metadata + def pre_get_playbook( self, request: playbook.GetPlaybookRequest, @@ -360,6 +430,52 @@ def post_get_playbook_version_with_metadata( """ return response, metadata + def pre_import_playbook( + self, + request: playbook.ImportPlaybookRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[playbook.ImportPlaybookRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for import_playbook + + Override in a subclass to manipulate the request or metadata + before they are sent to the Playbooks server. + """ + return request, metadata + + def post_import_playbook( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for import_playbook + + DEPRECATED. Please use the `post_import_playbook_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the Playbooks server but before + it is returned to user code. This `post_import_playbook` interceptor runs + before the `post_import_playbook_with_metadata` interceptor. + """ + return response + + def post_import_playbook_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for import_playbook + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the Playbooks server but before it is returned to user code. + + We recommend only using this `post_import_playbook_with_metadata` + interceptor in new development instead of the `post_import_playbook` interceptor. + When both interceptors are used, this `post_import_playbook_with_metadata` interceptor runs after the + `post_import_playbook` interceptor. The (possibly modified) response returned by + `post_import_playbook` will be passed to + `post_import_playbook_with_metadata`. + """ + return response, metadata + def pre_list_playbooks( self, request: playbook.ListPlaybooksRequest, @@ -456,6 +572,56 @@ def post_list_playbook_versions_with_metadata( """ return response, metadata + def pre_restore_playbook_version( + self, + request: playbook.RestorePlaybookVersionRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + playbook.RestorePlaybookVersionRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for restore_playbook_version + + Override in a subclass to manipulate the request or metadata + before they are sent to the Playbooks server. + """ + return request, metadata + + def post_restore_playbook_version( + self, response: playbook.RestorePlaybookVersionResponse + ) -> playbook.RestorePlaybookVersionResponse: + """Post-rpc interceptor for restore_playbook_version + + DEPRECATED. Please use the `post_restore_playbook_version_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the Playbooks server but before + it is returned to user code. This `post_restore_playbook_version` interceptor runs + before the `post_restore_playbook_version_with_metadata` interceptor. + """ + return response + + def post_restore_playbook_version_with_metadata( + self, + response: playbook.RestorePlaybookVersionResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + playbook.RestorePlaybookVersionResponse, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Post-rpc interceptor for restore_playbook_version + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the Playbooks server but before it is returned to user code. + + We recommend only using this `post_restore_playbook_version_with_metadata` + interceptor in new development instead of the `post_restore_playbook_version` interceptor. + When both interceptors are used, this `post_restore_playbook_version_with_metadata` interceptor runs after the + `post_restore_playbook_version` interceptor. The (possibly modified) response returned by + `post_restore_playbook_version` will be passed to + `post_restore_playbook_version_with_metadata`. + """ + return response, metadata + def pre_update_playbook( self, request: gcdc_playbook.UpdatePlaybookRequest, @@ -711,11 +877,70 @@ def __init__( self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST ) + self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None if client_cert_source_for_mtls: self._session.configure_mtls_channel(client_cert_source_for_mtls) self._interceptor = interceptor or PlaybooksRestInterceptor() self._prep_wrapped_messages(client_info) + @property + def operations_client(self) -> operations_v1.AbstractOperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Only create a new client if we do not already have one. + if self._operations_client is None: + http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v3beta1/{name=projects/*/operations/*}:cancel", + }, + { + "method": "post", + "uri": "/v3beta1/{name=projects/*/locations/*/operations/*}:cancel", + }, + ], + "google.longrunning.Operations.GetOperation": [ + { + "method": "get", + "uri": "/v3beta1/{name=projects/*/operations/*}", + }, + { + "method": "get", + "uri": "/v3beta1/{name=projects/*/locations/*/operations/*}", + }, + ], + "google.longrunning.Operations.ListOperations": [ + { + "method": "get", + "uri": "/v3beta1/{name=projects/*}/operations", + }, + { + "method": "get", + "uri": "/v3beta1/{name=projects/*/locations/*}/operations", + }, + ], + } + + rest_transport = operations_v1.OperationsRestTransport( + host=self._host, + # use the credentials which are saved + credentials=self._credentials, + scopes=self._scopes, + http_options=http_options, + path_prefix="v3beta1", + ) + + self._operations_client = operations_v1.AbstractOperationsClient( + transport=rest_transport + ) + + # Return the client from cache. + return self._operations_client + class _CreatePlaybook( _BasePlaybooksRestTransport._BaseCreatePlaybook, PlaybooksRestStub ): @@ -1261,6 +1486,164 @@ def __call__( if response.status_code >= 400: raise core_exceptions.from_http_response(response) + class _ExportPlaybook( + _BasePlaybooksRestTransport._BaseExportPlaybook, PlaybooksRestStub + ): + def __hash__(self): + return hash("PlaybooksRestTransport.ExportPlaybook") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: playbook.ExportPlaybookRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the export playbook method over HTTP. + + Args: + request (~.playbook.ExportPlaybookRequest): + The request object. The request message for + [Playbooks.ExportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BasePlaybooksRestTransport._BaseExportPlaybook._get_http_options() + ) + + request, metadata = self._interceptor.pre_export_playbook(request, metadata) + transcoded_request = ( + _BasePlaybooksRestTransport._BaseExportPlaybook._get_transcoded_request( + http_options, request + ) + ) + + body = ( + _BasePlaybooksRestTransport._BaseExportPlaybook._get_request_body_json( + transcoded_request + ) + ) + + # Jsonify the query params + query_params = ( + _BasePlaybooksRestTransport._BaseExportPlaybook._get_query_params_json( + transcoded_request + ) + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.dialogflow.cx_v3beta1.PlaybooksClient.ExportPlaybook", + extra={ + "serviceName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "rpcName": "ExportPlaybook", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = PlaybooksRestTransport._ExportPlaybook._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_export_playbook(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_export_playbook_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.dialogflow.cx_v3beta1.PlaybooksClient.export_playbook", + extra={ + "serviceName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "rpcName": "ExportPlaybook", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + class _GetPlaybook(_BasePlaybooksRestTransport._BaseGetPlaybook, PlaybooksRestStub): def __hash__(self): return hash("PlaybooksRestTransport.GetPlaybook") @@ -1570,11 +1953,11 @@ def __call__( ) return resp - class _ListPlaybooks( - _BasePlaybooksRestTransport._BaseListPlaybooks, PlaybooksRestStub + class _ImportPlaybook( + _BasePlaybooksRestTransport._BaseImportPlaybook, PlaybooksRestStub ): def __hash__(self): - return hash("PlaybooksRestTransport.ListPlaybooks") + return hash("PlaybooksRestTransport.ImportPlaybook") @staticmethod def _get_response( @@ -1595,17 +1978,175 @@ def _get_response( timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, ) return response def __call__( self, - request: playbook.ListPlaybooksRequest, + request: playbook.ImportPlaybookRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> playbook.ListPlaybooksResponse: + ) -> operations_pb2.Operation: + r"""Call the import playbook method over HTTP. + + Args: + request (~.playbook.ImportPlaybookRequest): + The request object. The request message for + [Playbooks.ImportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BasePlaybooksRestTransport._BaseImportPlaybook._get_http_options() + ) + + request, metadata = self._interceptor.pre_import_playbook(request, metadata) + transcoded_request = ( + _BasePlaybooksRestTransport._BaseImportPlaybook._get_transcoded_request( + http_options, request + ) + ) + + body = ( + _BasePlaybooksRestTransport._BaseImportPlaybook._get_request_body_json( + transcoded_request + ) + ) + + # Jsonify the query params + query_params = ( + _BasePlaybooksRestTransport._BaseImportPlaybook._get_query_params_json( + transcoded_request + ) + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.dialogflow.cx_v3beta1.PlaybooksClient.ImportPlaybook", + extra={ + "serviceName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "rpcName": "ImportPlaybook", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = PlaybooksRestTransport._ImportPlaybook._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_import_playbook(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_import_playbook_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.dialogflow.cx_v3beta1.PlaybooksClient.import_playbook", + extra={ + "serviceName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "rpcName": "ImportPlaybook", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _ListPlaybooks( + _BasePlaybooksRestTransport._BaseListPlaybooks, PlaybooksRestStub + ): + def __hash__(self): + return hash("PlaybooksRestTransport.ListPlaybooks") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: playbook.ListPlaybooksRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> playbook.ListPlaybooksResponse: r"""Call the list playbooks method over HTTP. Args: @@ -1872,6 +2413,163 @@ def __call__( ) return resp + class _RestorePlaybookVersion( + _BasePlaybooksRestTransport._BaseRestorePlaybookVersion, PlaybooksRestStub + ): + def __hash__(self): + return hash("PlaybooksRestTransport.RestorePlaybookVersion") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: playbook.RestorePlaybookVersionRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> playbook.RestorePlaybookVersionResponse: + r"""Call the restore playbook version method over HTTP. + + Args: + request (~.playbook.RestorePlaybookVersionRequest): + The request object. The request message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.playbook.RestorePlaybookVersionResponse: + The response message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + + """ + + http_options = ( + _BasePlaybooksRestTransport._BaseRestorePlaybookVersion._get_http_options() + ) + + request, metadata = self._interceptor.pre_restore_playbook_version( + request, metadata + ) + transcoded_request = _BasePlaybooksRestTransport._BaseRestorePlaybookVersion._get_transcoded_request( + http_options, request + ) + + body = _BasePlaybooksRestTransport._BaseRestorePlaybookVersion._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BasePlaybooksRestTransport._BaseRestorePlaybookVersion._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.dialogflow.cx_v3beta1.PlaybooksClient.RestorePlaybookVersion", + extra={ + "serviceName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "rpcName": "RestorePlaybookVersion", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = PlaybooksRestTransport._RestorePlaybookVersion._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = playbook.RestorePlaybookVersionResponse() + pb_resp = playbook.RestorePlaybookVersionResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_restore_playbook_version(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_restore_playbook_version_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = playbook.RestorePlaybookVersionResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.dialogflow.cx_v3beta1.PlaybooksClient.restore_playbook_version", + extra={ + "serviceName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "rpcName": "RestorePlaybookVersion", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + class _UpdatePlaybook( _BasePlaybooksRestTransport._BaseUpdatePlaybook, PlaybooksRestStub ): @@ -2074,6 +2772,14 @@ def delete_playbook_version( # In C++ this would require a dynamic_cast return self._DeletePlaybookVersion(self._session, self._host, self._interceptor) # type: ignore + @property + def export_playbook( + self, + ) -> Callable[[playbook.ExportPlaybookRequest], operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ExportPlaybook(self._session, self._host, self._interceptor) # type: ignore + @property def get_playbook( self, @@ -2090,6 +2796,14 @@ def get_playbook_version( # In C++ this would require a dynamic_cast return self._GetPlaybookVersion(self._session, self._host, self._interceptor) # type: ignore + @property + def import_playbook( + self, + ) -> Callable[[playbook.ImportPlaybookRequest], operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ImportPlaybook(self._session, self._host, self._interceptor) # type: ignore + @property def list_playbooks( self, @@ -2108,6 +2822,17 @@ def list_playbook_versions( # In C++ this would require a dynamic_cast return self._ListPlaybookVersions(self._session, self._host, self._interceptor) # type: ignore + @property + def restore_playbook_version( + self, + ) -> Callable[ + [playbook.RestorePlaybookVersionRequest], + playbook.RestorePlaybookVersionResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._RestorePlaybookVersion(self._session, self._host, self._interceptor) # type: ignore + @property def update_playbook( self, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest_base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest_base.py index 7b9de0512d1a..4dfa57c6b441 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest_base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest_base.py @@ -299,6 +299,63 @@ def _get_query_params_json(transcoded_request): query_params["$alt"] = "json;enum-encoding=int" return query_params + class _BaseExportPlaybook: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*}:export", + "body": "*", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = playbook.ExportPlaybookRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BasePlaybooksRestTransport._BaseExportPlaybook._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseGetPlaybook: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") @@ -393,6 +450,63 @@ def _get_query_params_json(transcoded_request): query_params["$alt"] = "json;enum-encoding=int" return query_params + class _BaseImportPlaybook: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v3beta1/{parent=projects/*/locations/*/agents/*}/playbooks:import", + "body": "*", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = playbook.ImportPlaybookRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BasePlaybooksRestTransport._BaseImportPlaybook._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseListPlaybooks: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") @@ -487,6 +601,63 @@ def _get_query_params_json(transcoded_request): query_params["$alt"] = "json;enum-encoding=int" return query_params + class _BaseRestorePlaybookVersion: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*/versions/*}:restore", + "body": "*", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = playbook.RestorePlaybookVersionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BasePlaybooksRestTransport._BaseRestorePlaybookVersion._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + class _BaseUpdatePlaybook: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py index f0599564dc09..907af0939f39 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py @@ -90,6 +90,8 @@ class SessionsAsyncClient: parse_example_path = staticmethod(SessionsClient.parse_example_path) flow_path = staticmethod(SessionsClient.flow_path) parse_flow_path = staticmethod(SessionsClient.parse_flow_path) + generator_path = staticmethod(SessionsClient.generator_path) + parse_generator_path = staticmethod(SessionsClient.parse_generator_path) intent_path = staticmethod(SessionsClient.intent_path) parse_intent_path = staticmethod(SessionsClient.parse_intent_path) page_path = staticmethod(SessionsClient.page_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py index e0acbced9c29..9742b3651e3c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py @@ -298,6 +298,30 @@ def parse_flow_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def generator_path( + project: str, + location: str, + agent: str, + generator: str, + ) -> str: + """Returns a fully-qualified generator string.""" + return "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + + @staticmethod + def parse_generator_path(path: str) -> Dict[str, str]: + """Parses a generator path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/generators/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def intent_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py index 8cab5fb95693..d12cd83cc263 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py @@ -92,6 +92,8 @@ class TestCasesAsyncClient: parse_environment_path = staticmethod(TestCasesClient.parse_environment_path) flow_path = staticmethod(TestCasesClient.flow_path) parse_flow_path = staticmethod(TestCasesClient.parse_flow_path) + generator_path = staticmethod(TestCasesClient.generator_path) + parse_generator_path = staticmethod(TestCasesClient.parse_generator_path) intent_path = staticmethod(TestCasesClient.intent_path) parse_intent_path = staticmethod(TestCasesClient.parse_intent_path) page_path = staticmethod(TestCasesClient.page_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py index cda7053350cc..c418fab274fb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py @@ -299,6 +299,30 @@ def parse_flow_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def generator_path( + project: str, + location: str, + agent: str, + generator: str, + ) -> str: + """Returns a fully-qualified generator string.""" + return "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + + @staticmethod + def parse_generator_path(path: str) -> Dict[str, str]: + """Parses a generator path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/generators/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def intent_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py index 40ff9303ff9e..fe0e92c3e954 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py @@ -83,6 +83,8 @@ class ToolsAsyncClient: _DEFAULT_ENDPOINT_TEMPLATE = ToolsClient._DEFAULT_ENDPOINT_TEMPLATE _DEFAULT_UNIVERSE = ToolsClient._DEFAULT_UNIVERSE + secret_version_path = staticmethod(ToolsClient.secret_version_path) + parse_secret_version_path = staticmethod(ToolsClient.parse_secret_version_path) service_path = staticmethod(ToolsClient.service_path) parse_service_path = staticmethod(ToolsClient.parse_service_path) tool_path = staticmethod(ToolsClient.tool_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py index f533d84f467c..628db6f7752a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py @@ -204,6 +204,28 @@ def transport(self) -> ToolsTransport: """ return self._transport + @staticmethod + def secret_version_path( + project: str, + secret: str, + version: str, + ) -> str: + """Returns a fully-qualified secret_version string.""" + return "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + + @staticmethod + def parse_secret_version_path(path: str) -> Dict[str, str]: + """Parses a secret_version path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/secrets/(?P.+?)/versions/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def service_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py index f36e8b595b64..6f695586e669 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py @@ -85,6 +85,10 @@ class TransitionRouteGroupsAsyncClient: flow_path = staticmethod(TransitionRouteGroupsClient.flow_path) parse_flow_path = staticmethod(TransitionRouteGroupsClient.parse_flow_path) + generator_path = staticmethod(TransitionRouteGroupsClient.generator_path) + parse_generator_path = staticmethod( + TransitionRouteGroupsClient.parse_generator_path + ) intent_path = staticmethod(TransitionRouteGroupsClient.intent_path) parse_intent_path = staticmethod(TransitionRouteGroupsClient.parse_intent_path) page_path = staticmethod(TransitionRouteGroupsClient.page_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py index 17518950820c..fa92403de617 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py @@ -230,6 +230,30 @@ def parse_flow_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def generator_path( + project: str, + location: str, + agent: str, + generator: str, + ) -> str: + """Returns a fully-qualified generator string.""" + return "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + + @staticmethod + def parse_generator_path(path: str) -> Dict[str, str]: + """Parses a generator path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/generators/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def intent_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py index c8ff13937654..fa770c7434bf 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py @@ -81,6 +81,8 @@ class WebhooksAsyncClient: _DEFAULT_ENDPOINT_TEMPLATE = WebhooksClient._DEFAULT_ENDPOINT_TEMPLATE _DEFAULT_UNIVERSE = WebhooksClient._DEFAULT_UNIVERSE + secret_version_path = staticmethod(WebhooksClient.secret_version_path) + parse_secret_version_path = staticmethod(WebhooksClient.parse_secret_version_path) service_path = staticmethod(WebhooksClient.service_path) parse_service_path = staticmethod(WebhooksClient.parse_service_path) webhook_path = staticmethod(WebhooksClient.webhook_path) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py index 9c37e928af59..cb634b301dab 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py @@ -202,6 +202,28 @@ def transport(self) -> WebhooksTransport: """ return self._transport + @staticmethod + def secret_version_path( + project: str, + secret: str, + version: str, + ) -> str: + """Returns a fully-qualified secret_version string.""" + return "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + + @staticmethod + def parse_secret_version_path(path: str) -> Dict[str, str]: + """Parses a secret_version path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/secrets/(?P.+?)/versions/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def service_path( project: str, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/__init__.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/__init__.py index ab8af8824b7f..2e1faa5ef7cf 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/__init__.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/__init__.py @@ -107,22 +107,13 @@ UpdateEnvironmentRequest, ) from .example import ( - Action, - AgentUtterance, CreateExampleRequest, DeleteExampleRequest, Example, - FlowInvocation, GetExampleRequest, ListExamplesRequest, ListExamplesResponse, - OutputState, - PlaybookInput, - PlaybookInvocation, - PlaybookOutput, - ToolUse, UpdateExampleRequest, - UserUtterance, ) from .experiment import ( CreateExperimentRequest, @@ -202,21 +193,33 @@ TransitionRoute, UpdatePageRequest, ) -from .parameter_definition import ParameterDefinition +from .parameter_definition import ( + DataType, + InlineSchema, + ParameterDefinition, + TypeSchema, +) from .playbook import ( CreatePlaybookRequest, CreatePlaybookVersionRequest, DeletePlaybookRequest, DeletePlaybookVersionRequest, + ExportPlaybookRequest, + ExportPlaybookResponse, GetPlaybookRequest, GetPlaybookVersionRequest, Handler, + ImportPlaybookRequest, + ImportPlaybookResponse, ListPlaybooksRequest, ListPlaybooksResponse, ListPlaybookVersionsRequest, ListPlaybookVersionsResponse, Playbook, + PlaybookImportStrategy, PlaybookVersion, + RestorePlaybookVersionRequest, + RestorePlaybookVersionResponse, UpdatePlaybookRequest, ) from .response_message import ResponseMessage @@ -325,6 +328,26 @@ UpdateToolRequest, ) from .tool_call import ToolCall, ToolCallResult +from .trace import ( + Action, + AgentUtterance, + Event, + ExceptionDetail, + FlowInvocation, + FlowTransition, + LlmCall, + NamedMetric, + OutputState, + PlaybookInput, + PlaybookInvocation, + PlaybookOutput, + PlaybookTransition, + RetrievalStrategy, + Span, + Status, + ToolUse, + UserUtterance, +) from .transition_route_group import ( CreateTransitionRouteGroupRequest, DeleteTransitionRouteGroupRequest, @@ -441,22 +464,13 @@ "RunContinuousTestRequest", "RunContinuousTestResponse", "UpdateEnvironmentRequest", - "Action", - "AgentUtterance", "CreateExampleRequest", "DeleteExampleRequest", "Example", - "FlowInvocation", "GetExampleRequest", "ListExamplesRequest", "ListExamplesResponse", - "PlaybookInput", - "PlaybookInvocation", - "PlaybookOutput", - "ToolUse", "UpdateExampleRequest", - "UserUtterance", - "OutputState", "CreateExperimentRequest", "DeleteExperimentRequest", "Experiment", @@ -527,20 +541,30 @@ "Page", "TransitionRoute", "UpdatePageRequest", + "InlineSchema", "ParameterDefinition", + "TypeSchema", + "DataType", "CreatePlaybookRequest", "CreatePlaybookVersionRequest", "DeletePlaybookRequest", "DeletePlaybookVersionRequest", + "ExportPlaybookRequest", + "ExportPlaybookResponse", "GetPlaybookRequest", "GetPlaybookVersionRequest", "Handler", + "ImportPlaybookRequest", + "ImportPlaybookResponse", "ListPlaybooksRequest", "ListPlaybooksResponse", "ListPlaybookVersionsRequest", "ListPlaybookVersionsResponse", "Playbook", + "PlaybookImportStrategy", "PlaybookVersion", + "RestorePlaybookVersionRequest", + "RestorePlaybookVersionResponse", "UpdatePlaybookRequest", "ResponseMessage", "SafetySettings", @@ -639,6 +663,24 @@ "UpdateToolRequest", "ToolCall", "ToolCallResult", + "Action", + "AgentUtterance", + "Event", + "ExceptionDetail", + "FlowInvocation", + "FlowTransition", + "LlmCall", + "NamedMetric", + "PlaybookInput", + "PlaybookInvocation", + "PlaybookOutput", + "PlaybookTransition", + "Span", + "Status", + "ToolUse", + "UserUtterance", + "OutputState", + "RetrievalStrategy", "CreateTransitionRouteGroupRequest", "DeleteTransitionRouteGroupRequest", "GetTransitionRouteGroupRequest", diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/audio_config.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/audio_config.py index 72ee41c44f78..9a20e26410e0 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/audio_config.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/audio_config.py @@ -48,8 +48,8 @@ class AudioEncoding(proto.Enum): AUDIO_ENCODING_UNSPECIFIED (0): Not specified. AUDIO_ENCODING_LINEAR_16 (1): - Uncompressed 16-bit signed little-endian - samples (Linear PCM). + Uncompressed 16-bit signed little-endian samples (Linear + PCM). LINT: LEGACY_NAMES AUDIO_ENCODING_FLAC (2): ```FLAC`` `__ (Free Lossless Audio Codec) is the recommended encoding @@ -174,13 +174,13 @@ class OutputAudioEncoding(proto.Enum): OUTPUT_AUDIO_ENCODING_UNSPECIFIED (0): Not specified. OUTPUT_AUDIO_ENCODING_LINEAR_16 (1): - Uncompressed 16-bit signed little-endian - samples (Linear PCM). Audio content returned as - LINEAR16 also contains a WAV header. + Uncompressed 16-bit signed little-endian samples (Linear + PCM). Audio content returned as LINEAR16 also contains a WAV + header. LINT: LEGACY_NAMES OUTPUT_AUDIO_ENCODING_MP3 (2): MP3 audio at 32kbps. OUTPUT_AUDIO_ENCODING_MP3_64_KBPS (4): - MP3 audio at 64kbps. + MP3 audio at 64kbps. LINT: LEGACY_NAMES OUTPUT_AUDIO_ENCODING_OGG_OPUS (3): Opus encoded audio wrapped in an ogg container. The result will be a file which can diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/data_store_connection.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/data_store_connection.py index 1a3a038e1040..6562bd0f20ab 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/data_store_connection.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/data_store_connection.py @@ -17,6 +17,7 @@ from typing import MutableMapping, MutableSequence +from google.protobuf import struct_pb2 # type: ignore import proto # type: ignore __protobuf__ = proto.module( @@ -182,6 +183,8 @@ class SearchSnippet(proto.Message): for the document. text (str): Text included in the prompt. + metadata (google.protobuf.struct_pb2.Struct): + Metadata associated with the document. """ document_title: str = proto.Field( @@ -196,6 +199,11 @@ class SearchSnippet(proto.Message): proto.STRING, number=3, ) + metadata: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=5, + message=struct_pb2.Struct, + ) class AnswerGenerationModelCallSignals(proto.Message): r"""Diagnostic info related to the answer generation model call. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/environment.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/environment.py index 989b7c442c1f..56e4d4b62df0 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/environment.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/environment.py @@ -92,13 +92,16 @@ class VersionConfig(proto.Message): Attributes: version (str): - Required. Both flow and playbook versions are - supported. Format for flow version: + Required. Flow, playbook and tool versions + are supported. Format for flow version: projects//locations//agents//flows//versions/. Format for playbook version: projects//locations//agents//playbooks//versions/. + Format for tool version: + + projects//locations//agents//tools//versions/. """ version: str = proto.Field( diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/example.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/example.py index f207b5e52427..ddfd1d7b7adc 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/example.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/example.py @@ -18,14 +18,14 @@ from typing import MutableMapping, MutableSequence from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore +from google.cloud.dialogflowcx_v3beta1.types import trace + __protobuf__ = proto.module( package="google.cloud.dialogflow.cx.v3beta1", manifest={ - "OutputState", "CreateExampleRequest", "DeleteExampleRequest", "ListExamplesRequest", @@ -33,43 +33,10 @@ "GetExampleRequest", "UpdateExampleRequest", "Example", - "PlaybookInput", - "PlaybookOutput", - "Action", - "UserUtterance", - "AgentUtterance", - "ToolUse", - "PlaybookInvocation", - "FlowInvocation", }, ) -class OutputState(proto.Enum): - r"""Output state. - - Values: - OUTPUT_STATE_UNSPECIFIED (0): - Unspecified output. - OUTPUT_STATE_OK (1): - Succeeded. - OUTPUT_STATE_CANCELLED (2): - Cancelled. - OUTPUT_STATE_FAILED (3): - Failed. - OUTPUT_STATE_ESCALATED (4): - Escalated. - OUTPUT_STATE_PENDING (5): - Pending. - """ - OUTPUT_STATE_UNSPECIFIED = 0 - OUTPUT_STATE_OK = 1 - OUTPUT_STATE_CANCELLED = 2 - OUTPUT_STATE_FAILED = 3 - OUTPUT_STATE_ESCALATED = 4 - OUTPUT_STATE_PENDING = 5 - - class CreateExampleRequest(proto.Message): r"""The request message for [Examples.CreateExample][google.cloud.dialogflow.cx.v3beta1.Examples.CreateExample]. @@ -273,20 +240,20 @@ class Example(proto.Message): proto.STRING, number=1, ) - playbook_input: "PlaybookInput" = proto.Field( + playbook_input: trace.PlaybookInput = proto.Field( proto.MESSAGE, number=3, - message="PlaybookInput", + message=trace.PlaybookInput, ) - playbook_output: "PlaybookOutput" = proto.Field( + playbook_output: trace.PlaybookOutput = proto.Field( proto.MESSAGE, number=4, - message="PlaybookOutput", + message=trace.PlaybookOutput, ) - actions: MutableSequence["Action"] = proto.RepeatedField( + actions: MutableSequence[trace.Action] = proto.RepeatedField( proto.MESSAGE, number=2, - message="Action", + message=trace.Action, ) display_name: str = proto.Field( proto.STRING, @@ -310,10 +277,10 @@ class Example(proto.Message): number=11, message=timestamp_pb2.Timestamp, ) - conversation_state: "OutputState" = proto.Field( + conversation_state: trace.OutputState = proto.Field( proto.ENUM, number=12, - enum="OutputState", + enum=trace.OutputState, ) language_code: str = proto.Field( proto.STRING, @@ -321,285 +288,4 @@ class Example(proto.Message): ) -class PlaybookInput(proto.Message): - r"""Input of the playbook. - - Attributes: - preceding_conversation_summary (str): - Optional. Summary string of the preceding - conversation for the child playbook invocation. - action_parameters (google.protobuf.struct_pb2.Struct): - Optional. A list of input parameters for the - action. - """ - - preceding_conversation_summary: str = proto.Field( - proto.STRING, - number=1, - ) - action_parameters: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=3, - message=struct_pb2.Struct, - ) - - -class PlaybookOutput(proto.Message): - r"""Output of the playbook. - - Attributes: - execution_summary (str): - Optional. Summary string of the execution - result of the child playbook. - action_parameters (google.protobuf.struct_pb2.Struct): - Optional. A Struct object of output - parameters for the action. - """ - - execution_summary: str = proto.Field( - proto.STRING, - number=1, - ) - action_parameters: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=4, - message=struct_pb2.Struct, - ) - - -class Action(proto.Message): - r"""Action performed by end user or Dialogflow agent in the - conversation. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - user_utterance (google.cloud.dialogflowcx_v3beta1.types.UserUtterance): - Optional. Agent obtained a message from the - customer. - - This field is a member of `oneof`_ ``action``. - agent_utterance (google.cloud.dialogflowcx_v3beta1.types.AgentUtterance): - Optional. Action performed by the agent as a - message. - - This field is a member of `oneof`_ ``action``. - tool_use (google.cloud.dialogflowcx_v3beta1.types.ToolUse): - Optional. Action performed on behalf of the - agent by calling a plugin tool. - - This field is a member of `oneof`_ ``action``. - playbook_invocation (google.cloud.dialogflowcx_v3beta1.types.PlaybookInvocation): - Optional. Action performed on behalf of the - agent by invoking a child playbook. - - This field is a member of `oneof`_ ``action``. - flow_invocation (google.cloud.dialogflowcx_v3beta1.types.FlowInvocation): - Optional. Action performed on behalf of the - agent by invoking a CX flow. - - This field is a member of `oneof`_ ``action``. - """ - - user_utterance: "UserUtterance" = proto.Field( - proto.MESSAGE, - number=1, - oneof="action", - message="UserUtterance", - ) - agent_utterance: "AgentUtterance" = proto.Field( - proto.MESSAGE, - number=2, - oneof="action", - message="AgentUtterance", - ) - tool_use: "ToolUse" = proto.Field( - proto.MESSAGE, - number=3, - oneof="action", - message="ToolUse", - ) - playbook_invocation: "PlaybookInvocation" = proto.Field( - proto.MESSAGE, - number=4, - oneof="action", - message="PlaybookInvocation", - ) - flow_invocation: "FlowInvocation" = proto.Field( - proto.MESSAGE, - number=5, - oneof="action", - message="FlowInvocation", - ) - - -class UserUtterance(proto.Message): - r"""UserUtterance represents one message sent by the customer. - - Attributes: - text (str): - Required. Message content in text. - """ - - text: str = proto.Field( - proto.STRING, - number=1, - ) - - -class AgentUtterance(proto.Message): - r"""AgentUtterance represents one message sent by the agent. - - Attributes: - text (str): - Required. Message content in text. - """ - - text: str = proto.Field( - proto.STRING, - number=1, - ) - - -class ToolUse(proto.Message): - r"""Stores metadata of the invocation of an action supported by a - tool. - - Attributes: - tool (str): - Required. The - [tool][google.cloud.dialogflow.cx.v3beta1.Tool] that should - be used. Format: - ``projects//locations//agents//tools/``. - display_name (str): - Output only. The display name of the tool. - action (str): - Optional. Name of the action to be called - during the tool use. - input_action_parameters (google.protobuf.struct_pb2.Struct): - Optional. A list of input parameters for the - action. - output_action_parameters (google.protobuf.struct_pb2.Struct): - Optional. A list of output parameters - generated by the action. - """ - - tool: str = proto.Field( - proto.STRING, - number=1, - ) - display_name: str = proto.Field( - proto.STRING, - number=8, - ) - action: str = proto.Field( - proto.STRING, - number=2, - ) - input_action_parameters: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=5, - message=struct_pb2.Struct, - ) - output_action_parameters: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=6, - message=struct_pb2.Struct, - ) - - -class PlaybookInvocation(proto.Message): - r"""Stores metadata of the invocation of a child playbook. - - Attributes: - playbook (str): - Required. The unique identifier of the playbook. Format: - ``projects//locations//agents//playbooks/``. - display_name (str): - Output only. The display name of the - playbook. - playbook_input (google.cloud.dialogflowcx_v3beta1.types.PlaybookInput): - Optional. Input of the child playbook - invocation. - playbook_output (google.cloud.dialogflowcx_v3beta1.types.PlaybookOutput): - Optional. Output of the child playbook - invocation. - playbook_state (google.cloud.dialogflowcx_v3beta1.types.OutputState): - Required. Playbook invocation's output state. - """ - - playbook: str = proto.Field( - proto.STRING, - number=1, - ) - display_name: str = proto.Field( - proto.STRING, - number=5, - ) - playbook_input: "PlaybookInput" = proto.Field( - proto.MESSAGE, - number=2, - message="PlaybookInput", - ) - playbook_output: "PlaybookOutput" = proto.Field( - proto.MESSAGE, - number=3, - message="PlaybookOutput", - ) - playbook_state: "OutputState" = proto.Field( - proto.ENUM, - number=4, - enum="OutputState", - ) - - -class FlowInvocation(proto.Message): - r"""Stores metadata of the invocation of a CX flow. - - Attributes: - flow (str): - Required. The unique identifier of the flow. Format: - ``projects//locations//agents//flows/``. - display_name (str): - Output only. The display name of the flow. - input_action_parameters (google.protobuf.struct_pb2.Struct): - Optional. A list of input parameters for the - flow. - output_action_parameters (google.protobuf.struct_pb2.Struct): - Optional. A list of output parameters - generated by the flow invocation. - flow_state (google.cloud.dialogflowcx_v3beta1.types.OutputState): - Required. Flow invocation's output state. - """ - - flow: str = proto.Field( - proto.STRING, - number=1, - ) - display_name: str = proto.Field( - proto.STRING, - number=7, - ) - input_action_parameters: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=5, - message=struct_pb2.Struct, - ) - output_action_parameters: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=6, - message=struct_pb2.Struct, - ) - flow_state: "OutputState" = proto.Field( - proto.ENUM, - number=4, - enum="OutputState", - ) - - __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/flow.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/flow.py index 4b42db5f4d12..164074aae830 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/flow.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/flow.py @@ -24,6 +24,7 @@ from google.cloud.dialogflowcx_v3beta1.types import ( import_strategy, page, + parameter_definition, validation_message, ) from google.cloud.dialogflowcx_v3beta1.types import ( @@ -214,6 +215,12 @@ class Flow(proto.Message): level. knowledge_connector_settings (google.cloud.dialogflowcx_v3beta1.types.KnowledgeConnectorSettings): Optional. Knowledge connector configuration. + input_parameter_definitions (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.ParameterDefinition]): + Optional. Defined structured input parameters + for this flow. + output_parameter_definitions (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.ParameterDefinition]): + Optional. Defined structured output + parameters for this flow. multi_language_settings (google.cloud.dialogflowcx_v3beta1.types.Flow.MultiLanguageSettings): Optional. Multi-lingual agent settings for this flow. @@ -293,6 +300,20 @@ class MultiLanguageSettings(proto.Message): number=18, message=page.KnowledgeConnectorSettings, ) + input_parameter_definitions: MutableSequence[ + parameter_definition.ParameterDefinition + ] = proto.RepeatedField( + proto.MESSAGE, + number=26, + message=parameter_definition.ParameterDefinition, + ) + output_parameter_definitions: MutableSequence[ + parameter_definition.ParameterDefinition + ] = proto.RepeatedField( + proto.MESSAGE, + number=27, + message=parameter_definition.ParameterDefinition, + ) multi_language_settings: MultiLanguageSettings = proto.Field( proto.MESSAGE, number=28, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/fulfillment.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/fulfillment.py index 2d46611cdc44..1006935ff82b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/fulfillment.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/fulfillment.py @@ -100,6 +100,9 @@ class Fulfillment(proto.Message): in the fulfillment will be respected. This flag is only useful for fulfillments associated with no-match event handlers. + generators (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.Fulfillment.GeneratorSettings]): + A list of Generators to be called during this + fulfillment. """ class SetParameterAction(proto.Message): @@ -206,6 +209,47 @@ class CaseContent(proto.Message): message="Fulfillment.ConditionalCases.Case", ) + class GeneratorSettings(proto.Message): + r"""Generator settings used by the LLM to generate a text + response. + + Attributes: + generator (str): + Required. The generator to call. Format: + ``projects//locations//agents//generators/``. + input_parameters (MutableMapping[str, str]): + Map from [placeholder parameter][Generator.Parameter.id] in + the + [Generator][google.cloud.dialogflow.cx.v3beta1.Generator] to + corresponding session parameters. By default, Dialogflow + uses the session parameter with the same name to fill in the + generator template. e.g. If there is a placeholder parameter + ``city`` in the Generator, Dialogflow default to fill in the + ``$city`` with ``$session.params.city``. However, you may + choose to fill ``$city`` with + ``$session.params.desination-city``. + + - Map key: [parameter ID][Genrator.Parameter.id] + - Map value: session parameter name + output_parameter (str): + Required. Output parameter which should + contain the generator response. + """ + + generator: str = proto.Field( + proto.STRING, + number=1, + ) + input_parameters: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=2, + ) + output_parameter: str = proto.Field( + proto.STRING, + number=3, + ) + messages: MutableSequence[response_message.ResponseMessage] = proto.RepeatedField( proto.MESSAGE, number=1, @@ -242,6 +286,11 @@ class CaseContent(proto.Message): proto.BOOL, number=12, ) + generators: MutableSequence[GeneratorSettings] = proto.RepeatedField( + proto.MESSAGE, + number=13, + message=GeneratorSettings, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/generative_settings.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/generative_settings.py index 5d535577836c..7ffffad84dc7 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/generative_settings.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/generative_settings.py @@ -198,8 +198,100 @@ class LlmModelSettings(proto.Message): The selected LLM model. prompt_text (str): The custom prompt to use. + parameters (google.cloud.dialogflowcx_v3beta1.types.LlmModelSettings.Parameters): + Generative model parameters. """ + class Parameters(proto.Message): + r"""Generative model parameters to control the model behavior. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + temperature (float): + The temperature used for sampling during response + generation. Value ranges from 0 to 1. Temperature controls + the degree of randomness in token selection. Lower + temperature means less randomness, while higher temperature + means more randomness. Valid range: [0.0, 1.0] + + This field is a member of `oneof`_ ``_temperature``. + input_token_limit (google.cloud.dialogflowcx_v3beta1.types.LlmModelSettings.Parameters.InputTokenLimit): + The input token limit. + This setting is currently only supported by + playbooks. + + This field is a member of `oneof`_ ``_input_token_limit``. + output_token_limit (google.cloud.dialogflowcx_v3beta1.types.LlmModelSettings.Parameters.OutputTokenLimit): + The output token limit. This setting is currently only + supported by playbooks. Only one of output_token_limit and + max_output_tokens is allowed to be set. + + This field is a member of `oneof`_ ``_output_token_limit``. + """ + + class InputTokenLimit(proto.Enum): + r"""The input token limits for 1 LLM call. For the limit of each + model, see + https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models + for more information. + + Values: + INPUT_TOKEN_LIMIT_UNSPECIFIED (0): + Limit not specified. Treated as 'INPUT_TOKEN_LIMIT_SHORT'. + INPUT_TOKEN_LIMIT_SHORT (1): + Input token limit up to 8k. + INPUT_TOKEN_LIMIT_MEDIUM (2): + Input token limit up to 32k. + INPUT_TOKEN_LIMIT_LONG (3): + Input token limit up to 100k. + """ + INPUT_TOKEN_LIMIT_UNSPECIFIED = 0 + INPUT_TOKEN_LIMIT_SHORT = 1 + INPUT_TOKEN_LIMIT_MEDIUM = 2 + INPUT_TOKEN_LIMIT_LONG = 3 + + class OutputTokenLimit(proto.Enum): + r"""The output token limits for 1 LLM call. The limits are + subject to change. For the limit of each model, see + https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models + for more information. + + Values: + OUTPUT_TOKEN_LIMIT_UNSPECIFIED (0): + Limit not specified. + OUTPUT_TOKEN_LIMIT_SHORT (1): + Input token limit up to 512 tokens. + OUTPUT_TOKEN_LIMIT_MEDIUM (2): + Input token limit up to 1k. + OUTPUT_TOKEN_LIMIT_LONG (3): + Input token limit up to 2k. + """ + OUTPUT_TOKEN_LIMIT_UNSPECIFIED = 0 + OUTPUT_TOKEN_LIMIT_SHORT = 1 + OUTPUT_TOKEN_LIMIT_MEDIUM = 2 + OUTPUT_TOKEN_LIMIT_LONG = 3 + + temperature: float = proto.Field( + proto.FLOAT, + number=1, + optional=True, + ) + input_token_limit: "LlmModelSettings.Parameters.InputTokenLimit" = proto.Field( + proto.ENUM, + number=2, + optional=True, + enum="LlmModelSettings.Parameters.InputTokenLimit", + ) + output_token_limit: "LlmModelSettings.Parameters.OutputTokenLimit" = ( + proto.Field( + proto.ENUM, + number=3, + optional=True, + enum="LlmModelSettings.Parameters.OutputTokenLimit", + ) + ) + model: str = proto.Field( proto.STRING, number=1, @@ -208,6 +300,11 @@ class LlmModelSettings(proto.Message): proto.STRING, number=2, ) + parameters: Parameters = proto.Field( + proto.MESSAGE, + number=4, + message=Parameters, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/parameter_definition.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/parameter_definition.py index 673f3024a18e..3e1a35e46ca3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/parameter_definition.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/parameter_definition.py @@ -22,25 +22,50 @@ __protobuf__ = proto.module( package="google.cloud.dialogflow.cx.v3beta1", manifest={ + "DataType", "ParameterDefinition", + "TypeSchema", + "InlineSchema", }, ) +class DataType(proto.Enum): + r"""Defines data types that are supported for inlined schemas. These + types are consistent with + [google.protobuf.Value][google.protobuf.Value]. + + Values: + DATA_TYPE_UNSPECIFIED (0): + Not specified. + STRING (1): + Represents any string value. + NUMBER (2): + Represents any number value. + BOOLEAN (3): + Represents a boolean value. + ARRAY (6): + Represents a repeated value. + """ + DATA_TYPE_UNSPECIFIED = 0 + STRING = 1 + NUMBER = 2 + BOOLEAN = 3 + ARRAY = 6 + + class ParameterDefinition(proto.Message): r"""Defines the properties of a parameter. Used to define parameters used in the agent and the input / output parameters for each fulfillment. - (-- Next Id: 4 --) - (-- api-linter: core::0123::resource-annotation=disabled - aip.dev/not-precedent: ParameterDefinition is not an exposed - resource. --) Attributes: name (str): - Name of parameter. + Required. Name of parameter. type_ (google.cloud.dialogflowcx_v3beta1.types.ParameterDefinition.ParameterType): Type of parameter. + type_schema (google.cloud.dialogflowcx_v3beta1.types.TypeSchema): + Optional. Type schema of parameter. description (str): Human-readable description of the parameter. Limited to 300 characters. @@ -48,7 +73,7 @@ class ParameterDefinition(proto.Message): class ParameterType(proto.Enum): r"""Parameter types are used for validation. These types are consistent - with [google.protobuf.Value][]. + with [google.protobuf.Value][google.protobuf.Value]. Values: PARAMETER_TYPE_UNSPECIFIED (0): @@ -84,10 +109,95 @@ class ParameterType(proto.Enum): number=2, enum=ParameterType, ) + type_schema: "TypeSchema" = proto.Field( + proto.MESSAGE, + number=4, + message="TypeSchema", + ) description: str = proto.Field( proto.STRING, number=3, ) +class TypeSchema(proto.Message): + r"""Encapsulates different type schema variations: either a + reference to an a schema that's already defined by a tool, or an + inline definition. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + inline_schema (google.cloud.dialogflowcx_v3beta1.types.InlineSchema): + Set if this is an inline schema definition. + + This field is a member of `oneof`_ ``schema``. + schema_reference (google.cloud.dialogflowcx_v3beta1.types.TypeSchema.SchemaReference): + Set if this is a schema reference. + + This field is a member of `oneof`_ ``schema``. + """ + + class SchemaReference(proto.Message): + r"""A reference to the schema of an existing tool. + + Attributes: + tool (str): + The tool that contains this schema definition. Format: + ``projects//locations//agents//tools/``. + schema (str): + The name of the schema. + """ + + tool: str = proto.Field( + proto.STRING, + number=1, + ) + schema: str = proto.Field( + proto.STRING, + number=2, + ) + + inline_schema: "InlineSchema" = proto.Field( + proto.MESSAGE, + number=1, + oneof="schema", + message="InlineSchema", + ) + schema_reference: SchemaReference = proto.Field( + proto.MESSAGE, + number=2, + oneof="schema", + message=SchemaReference, + ) + + +class InlineSchema(proto.Message): + r"""A type schema object that's specified inline. + + Attributes: + type_ (google.cloud.dialogflowcx_v3beta1.types.DataType): + Data type of the schema. + items (google.cloud.dialogflowcx_v3beta1.types.TypeSchema): + Schema of the elements if this is an ARRAY + type. + """ + + type_: "DataType" = proto.Field( + proto.ENUM, + number=1, + enum="DataType", + ) + items: "TypeSchema" = proto.Field( + proto.MESSAGE, + number=2, + message="TypeSchema", + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/playbook.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/playbook.py index 702f31d3c1cf..97cea8330a02 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/playbook.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/playbook.py @@ -21,12 +21,13 @@ from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore +from google.cloud.dialogflowcx_v3beta1.types import fulfillment as gcdc_fulfillment from google.cloud.dialogflowcx_v3beta1.types import ( - generative_settings, - parameter_definition, + import_strategy as gcdc_import_strategy, ) -from google.cloud.dialogflowcx_v3beta1.types import fulfillment as gcdc_fulfillment from google.cloud.dialogflowcx_v3beta1.types import advanced_settings, example +from google.cloud.dialogflowcx_v3beta1.types import generative_settings +from google.cloud.dialogflowcx_v3beta1.types import parameter_definition __protobuf__ = proto.module( package="google.cloud.dialogflow.cx.v3beta1", @@ -41,9 +42,16 @@ "CreatePlaybookVersionRequest", "PlaybookVersion", "GetPlaybookVersionRequest", + "RestorePlaybookVersionRequest", + "RestorePlaybookVersionResponse", "ListPlaybookVersionsRequest", "ListPlaybookVersionsResponse", "DeletePlaybookVersionRequest", + "ExportPlaybookRequest", + "ImportPlaybookRequest", + "PlaybookImportStrategy", + "ImportPlaybookResponse", + "ExportPlaybookResponse", "Handler", }, ) @@ -252,8 +260,25 @@ class Playbook(proto.Message): handlers (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.Handler]): Optional. A list of registered handlers to execute based on the specified triggers. + playbook_type (google.cloud.dialogflowcx_v3beta1.types.Playbook.PlaybookType): + Optional. Type of the playbook. """ + class PlaybookType(proto.Enum): + r"""Type of the playbook. + + Values: + PLAYBOOK_TYPE_UNSPECIFIED (0): + Unspecified type. Default to TASK. + TASK (1): + Task playbook. + ROUTINE (3): + Routine playbook. + """ + PLAYBOOK_TYPE_UNSPECIFIED = 0 + TASK = 1 + ROUTINE = 3 + class Step(proto.Message): r"""Message of single step execution. @@ -377,6 +402,11 @@ class Instruction(proto.Message): number=16, message="Handler", ) + playbook_type: PlaybookType = proto.Field( + proto.ENUM, + number=19, + enum=PlaybookType, + ) class CreatePlaybookVersionRequest(proto.Message): @@ -466,6 +496,38 @@ class GetPlaybookVersionRequest(proto.Message): ) +class RestorePlaybookVersionRequest(proto.Message): + r"""The request message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + + Attributes: + name (str): + Required. The name of the playbook version. Format: + ``projects//locations//agents//playbooks//versions/``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class RestorePlaybookVersionResponse(proto.Message): + r"""The response message for + [Playbooks.RestorePlaybookVersion][google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion]. + + Attributes: + playbook (google.cloud.dialogflowcx_v3beta1.types.Playbook): + The updated playbook. + """ + + playbook: "Playbook" = proto.Field( + proto.MESSAGE, + number=2, + message="Playbook", + ) + + class ListPlaybookVersionsRequest(proto.Message): r"""The request message for [Playbooks.ListPlaybookVersions][google.cloud.dialogflow.cx.v3beta1.Playbooks.ListPlaybookVersions]. @@ -544,6 +606,242 @@ class DeletePlaybookVersionRequest(proto.Message): ) +class ExportPlaybookRequest(proto.Message): + r"""The request message for + [Playbooks.ExportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook]. + + Attributes: + name (str): + Required. The name of the playbook to export. Format: + ``projects//locations//agents//playbooks/``. + playbook_uri (str): + Optional. The `Google Cloud + Storage `__ URI to + export the playbook to. The format of this URI must be + ``gs:///``. If left unspecified, + the serialized playbook is returned inline. + + Dialogflow performs a write operation for the Cloud Storage + object on the caller's behalf, so your request + authentication must have write permissions for the object. + For more information, see `Dialogflow access + control `__. + data_format (google.cloud.dialogflowcx_v3beta1.types.ExportPlaybookRequest.DataFormat): + Optional. The data format of the exported agent. If not + specified, ``BLOB`` is assumed. + """ + + class DataFormat(proto.Enum): + r"""Data format of the exported playbook. + + Values: + DATA_FORMAT_UNSPECIFIED (0): + Unspecified format. + BLOB (1): + Flow content will be exported as raw bytes. + JSON (2): + Flow content will be exported in JSON format. + """ + DATA_FORMAT_UNSPECIFIED = 0 + BLOB = 1 + JSON = 2 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + playbook_uri: str = proto.Field( + proto.STRING, + number=2, + ) + data_format: DataFormat = proto.Field( + proto.ENUM, + number=3, + enum=DataFormat, + ) + + +class ImportPlaybookRequest(proto.Message): + r"""The request message for + [Playbooks.ImportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook]. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + parent (str): + Required. The agent to import the playbook into. Format: + ``projects//locations//agents/``. + playbook_uri (str): + [Dialogflow access control] + (https://cloud.google.com/dialogflow/cx/docs/concept/access-control#storage). + + This field is a member of `oneof`_ ``playbook``. + playbook_content (bytes): + Uncompressed raw byte content for playbook. + + This field is a member of `oneof`_ ``playbook``. + import_strategy (google.cloud.dialogflowcx_v3beta1.types.PlaybookImportStrategy): + Optional. Specifies the import strategy used + when resolving resource conflicts. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + playbook_uri: str = proto.Field( + proto.STRING, + number=2, + oneof="playbook", + ) + playbook_content: bytes = proto.Field( + proto.BYTES, + number=3, + oneof="playbook", + ) + import_strategy: "PlaybookImportStrategy" = proto.Field( + proto.MESSAGE, + number=4, + message="PlaybookImportStrategy", + ) + + +class PlaybookImportStrategy(proto.Message): + r"""The playbook import strategy used for resource conflict resolution + associated with an + [ImportPlaybookRequest][google.cloud.dialogflow.cx.v3beta1.ImportPlaybookRequest]. + + Attributes: + main_playbook_import_strategy (google.cloud.dialogflowcx_v3beta1.types.ImportStrategy): + Optional. Specifies the import strategy used when resolving + conflicts with the main playbook. If not specified, + 'CREATE_NEW' is assumed. + nested_resource_import_strategy (google.cloud.dialogflowcx_v3beta1.types.ImportStrategy): + Optional. Specifies the import strategy used when resolving + referenced playbook/flow conflicts. If not specified, + 'CREATE_NEW' is assumed. + tool_import_strategy (google.cloud.dialogflowcx_v3beta1.types.ImportStrategy): + Optional. Specifies the import strategy used when resolving + tool conflicts. If not specified, 'CREATE_NEW' is assumed. + This will be applied after the main playbook and nested + resource import strategies, meaning if the playbook that + references the tool is skipped, the tool will also be + skipped. + """ + + main_playbook_import_strategy: gcdc_import_strategy.ImportStrategy = proto.Field( + proto.ENUM, + number=4, + enum=gcdc_import_strategy.ImportStrategy, + ) + nested_resource_import_strategy: gcdc_import_strategy.ImportStrategy = proto.Field( + proto.ENUM, + number=5, + enum=gcdc_import_strategy.ImportStrategy, + ) + tool_import_strategy: gcdc_import_strategy.ImportStrategy = proto.Field( + proto.ENUM, + number=6, + enum=gcdc_import_strategy.ImportStrategy, + ) + + +class ImportPlaybookResponse(proto.Message): + r"""The response message for + [Playbooks.ImportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook]. + + Attributes: + playbook (str): + The unique identifier of the new playbook. Format: + ``projects//locations//agents//playbooks/``. + conflicting_resources (google.cloud.dialogflowcx_v3beta1.types.ImportPlaybookResponse.ConflictingResources): + Info which resources have conflicts when + [REPORT_CONFLICTS][ImportPlaybookResponse.REPORT_CONFLICTS] + import strategy is set for all resources in + ImportPlaybookRequest. + """ + + class ConflictingResources(proto.Message): + r"""Conflicting resources detected during the import process. Only + filled when + [REPORT_CONFLICTS][ImportPlaybookResponse.REPORT_CONFLICTS] is set + in the request and there are conflicts in the display names. + + Attributes: + main_playbook_display_name (str): + Display name of conflicting main playbook. + nested_playbook_display_names (MutableSequence[str]): + Display names of conflicting nested + playbooks. + tool_display_names (MutableSequence[str]): + Display names of conflicting tools. + """ + + main_playbook_display_name: str = proto.Field( + proto.STRING, + number=1, + ) + nested_playbook_display_names: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + tool_display_names: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=3, + ) + + playbook: str = proto.Field( + proto.STRING, + number=1, + ) + conflicting_resources: ConflictingResources = proto.Field( + proto.MESSAGE, + number=2, + message=ConflictingResources, + ) + + +class ExportPlaybookResponse(proto.Message): + r"""The response message for + [Playbooks.ExportPlaybook][google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook]. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + playbook_uri (str): + The URI to a file containing the exported playbook. This + field is populated only if ``playbook_uri`` is specified in + [ExportPlaybookRequest][google.cloud.dialogflow.cx.v3beta1.ExportPlaybookRequest]. + + This field is a member of `oneof`_ ``playbook``. + playbook_content (bytes): + Uncompressed raw byte content for playbook. + + This field is a member of `oneof`_ ``playbook``. + """ + + playbook_uri: str = proto.Field( + proto.STRING, + number=1, + oneof="playbook", + ) + playbook_content: bytes = proto.Field( + proto.BYTES, + number=2, + oneof="playbook", + ) + + class Handler(proto.Message): r"""Handler can be used to define custom logic to be executed based on the user-specified triggers. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/safety_settings.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/safety_settings.py index e9c3bd55971e..a320229b51aa 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/safety_settings.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/safety_settings.py @@ -36,6 +36,9 @@ class SafetySettings(proto.Message): banned phrases. banned_phrases (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.SafetySettings.Phrase]): Banned phrases for generated text. + prompt_security_settings (google.cloud.dialogflowcx_v3beta1.types.SafetySettings.PromptSecuritySettings): + Optional. Settings for prompt security + checks. """ class PhraseMatchStrategy(proto.Enum): @@ -77,6 +80,19 @@ class Phrase(proto.Message): number=2, ) + class PromptSecuritySettings(proto.Message): + r"""Settings for prompt security checks. + + Attributes: + enable_prompt_security (bool): + Optional. Enable prompt security checks. + """ + + enable_prompt_security: bool = proto.Field( + proto.BOOL, + number=1, + ) + default_banned_phrase_match_strategy: PhraseMatchStrategy = proto.Field( proto.ENUM, number=4, @@ -87,6 +103,11 @@ class Phrase(proto.Message): number=1, message=Phrase, ) + prompt_security_settings: PromptSecuritySettings = proto.Field( + proto.MESSAGE, + number=8, + message=PromptSecuritySettings, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/security_settings.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/security_settings.py index 54bf89261144..9a4a36778aa8 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/security_settings.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/security_settings.py @@ -372,7 +372,10 @@ class AudioExportSettings(proto.Message): should have the permission of storage.buckets.setIamPolicy. audio_export_pattern (str): - Filename pattern for exported audio. + Filename pattern for exported audio. {conversation} and + {timestamp} are placeholders that will be replaced with the + conversation ID and epoch micros of the conversation. For + example, "{conversation}/recording\_{timestamp}.mulaw". enable_audio_redaction (bool): Enable audio redaction if it is true. Note that this only redacts end-user audio data; diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/session.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/session.py index dc5337e3b17d..b88c2206bf38 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/session.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/session.py @@ -854,6 +854,15 @@ class QueryParameters(proto.Message): - MapValue value: If parameter's entity type is a composite entity then use map from composite entity property names to property values, otherwise, use parameter value. + parameter_scope (str): + Scope for the parameters. If not specified, parameters will + be treated as session parameters. Parameters with custom + scope will not be put into [session + parameters][google.cloud.dialogflow.cx.v3beta1.SessionInfo.parameters]. + + You can reference the parameters with custom scope in the + agent with the following format: + $parameter-scope.params.parameter-id. current_page (str): The unique identifier of the [page][google.cloud.dialogflow.cx.v3beta1.Page] to override @@ -987,6 +996,10 @@ class QueryParameters(proto.Message): number=5, message=struct_pb2.Struct, ) + parameter_scope: str = proto.Field( + proto.STRING, + number=12, + ) current_page: str = proto.Field( proto.STRING, number=6, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/tool.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/tool.py index 41a91954b572..d25e6a3143ce 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/tool.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/tool.py @@ -196,12 +196,9 @@ class DataFormat(proto.Enum): Unspecified format. Treated as ``BLOB``. BLOB (1): Tools will be exported as raw bytes. - JSON (2): - Tools will be exported in JSON format. """ DATA_FORMAT_UNSPECIFIED = 0 BLOB = 1 - JSON = 2 parent: str = proto.Field( proto.STRING, @@ -698,6 +695,11 @@ class ApiKeyConfig(proto.Message): api_key (str): Optional. The API key. If the ``secret_version_for_api_key`` field is set, this field will be ignored. + secret_version_for_api_key (str): + Optional. The name of the SecretManager secret version + resource storing the API key. If this field is set, the + ``api_key`` field will be ignored. Format: + ``projects/{project}/secrets/{secret}/versions/{version}`` request_location (google.cloud.dialogflowcx_v3beta1.types.Tool.Authentication.RequestLocation): Required. Key location in the request. """ @@ -710,6 +712,10 @@ class ApiKeyConfig(proto.Message): proto.STRING, number=2, ) + secret_version_for_api_key: str = proto.Field( + proto.STRING, + number=4, + ) request_location: "Tool.Authentication.RequestLocation" = proto.Field( proto.ENUM, number=3, @@ -729,6 +735,11 @@ class OAuthConfig(proto.Message): Optional. The client secret from the OAuth provider. If the ``secret_version_for_client_secret`` field is set, this field will be ignored. + secret_version_for_client_secret (str): + Optional. The name of the SecretManager secret version + resource storing the client secret. If this field is set, + the ``client_secret`` field will be ignored. Format: + ``projects/{project}/secrets/{secret}/versions/{version}`` token_endpoint (str): Required. The token endpoint in the OAuth provider to exchange for an access token. @@ -766,6 +777,10 @@ class OauthGrantType(proto.Enum): proto.STRING, number=3, ) + secret_version_for_client_secret: str = proto.Field( + proto.STRING, + number=6, + ) token_endpoint: str = proto.Field( proto.STRING, number=4, @@ -827,12 +842,21 @@ class BearerTokenConfig(proto.Message): reference `__ can be used to pass the token dynamically, e.g. ``$session.params.parameter-id``. + secret_version_for_token (str): + Optional. The name of the SecretManager secret version + resource storing the Bearer token. If this field is set, the + ``token`` field will be ignored. Format: + ``projects/{project}/secrets/{secret}/versions/{version}`` """ token: str = proto.Field( proto.STRING, number=1, ) + secret_version_for_token: str = proto.Field( + proto.STRING, + number=2, + ) api_key_config: "Tool.Authentication.ApiKeyConfig" = proto.Field( proto.MESSAGE, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/trace.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/trace.py new file mode 100644 index 000000000000..6fa43d59ab84 --- /dev/null +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/trace.py @@ -0,0 +1,1050 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import proto # type: ignore + +from google.cloud.dialogflowcx_v3beta1.types import data_store_connection + +__protobuf__ = proto.module( + package="google.cloud.dialogflow.cx.v3beta1", + manifest={ + "OutputState", + "RetrievalStrategy", + "Action", + "UserUtterance", + "Event", + "AgentUtterance", + "ToolUse", + "LlmCall", + "PlaybookInvocation", + "FlowInvocation", + "PlaybookTransition", + "FlowTransition", + "PlaybookInput", + "PlaybookOutput", + "Span", + "NamedMetric", + "Status", + "ExceptionDetail", + }, +) + + +class OutputState(proto.Enum): + r"""Output state. + + Values: + OUTPUT_STATE_UNSPECIFIED (0): + Unspecified output. + OUTPUT_STATE_OK (1): + Succeeded. + OUTPUT_STATE_CANCELLED (2): + Cancelled. + OUTPUT_STATE_FAILED (3): + Failed. + OUTPUT_STATE_ESCALATED (4): + Escalated. + OUTPUT_STATE_PENDING (5): + Pending. + """ + OUTPUT_STATE_UNSPECIFIED = 0 + OUTPUT_STATE_OK = 1 + OUTPUT_STATE_CANCELLED = 2 + OUTPUT_STATE_FAILED = 3 + OUTPUT_STATE_ESCALATED = 4 + OUTPUT_STATE_PENDING = 5 + + +class RetrievalStrategy(proto.Enum): + r"""Retrieval strategy on how the example is selected to be fed + to the prompt. + + Values: + RETRIEVAL_STRATEGY_UNSPECIFIED (0): + Not specified. ``DEFAULT`` will be used. + DEFAULT (1): + Default retrieval strategy. + STATIC (2): + Static example will always be inserted to the + prompt. + NEVER (3): + Example will never be inserted into the + prompt. + """ + RETRIEVAL_STRATEGY_UNSPECIFIED = 0 + DEFAULT = 1 + STATIC = 2 + NEVER = 3 + + +class Action(proto.Message): + r"""Action performed by end user or Dialogflow agent in the + conversation. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + user_utterance (google.cloud.dialogflowcx_v3beta1.types.UserUtterance): + Optional. Agent obtained a message from the + customer. + + This field is a member of `oneof`_ ``action``. + event (google.cloud.dialogflowcx_v3beta1.types.Event): + Optional. The agent received an event from + the customer or a system event is emitted. + + This field is a member of `oneof`_ ``action``. + agent_utterance (google.cloud.dialogflowcx_v3beta1.types.AgentUtterance): + Optional. Action performed by the agent as a + message. + + This field is a member of `oneof`_ ``action``. + tool_use (google.cloud.dialogflowcx_v3beta1.types.ToolUse): + Optional. Action performed on behalf of the + agent by calling a plugin tool. + + This field is a member of `oneof`_ ``action``. + llm_call (google.cloud.dialogflowcx_v3beta1.types.LlmCall): + Optional. Output only. LLM call performed by + the agent. + + This field is a member of `oneof`_ ``action``. + intent_match (google.cloud.dialogflowcx_v3beta1.types.Action.IntentMatch): + Optional. Output only. Intent Match in flows. + + This field is a member of `oneof`_ ``action``. + flow_state_update (google.cloud.dialogflowcx_v3beta1.types.Action.FlowStateUpdate): + Optional. Output only. The state machine + update in flows. + + This field is a member of `oneof`_ ``action``. + playbook_invocation (google.cloud.dialogflowcx_v3beta1.types.PlaybookInvocation): + Optional. Action performed on behalf of the + agent by invoking a child playbook. + + This field is a member of `oneof`_ ``action``. + flow_invocation (google.cloud.dialogflowcx_v3beta1.types.FlowInvocation): + Optional. Action performed on behalf of the + agent by invoking a CX flow. + + This field is a member of `oneof`_ ``action``. + playbook_transition (google.cloud.dialogflowcx_v3beta1.types.PlaybookTransition): + Optional. Action performed on behalf of the + agent by transitioning to a target playbook. + + This field is a member of `oneof`_ ``action``. + flow_transition (google.cloud.dialogflowcx_v3beta1.types.FlowTransition): + Optional. Action performed on behalf of the + agent by transitioning to a target CX flow. + + This field is a member of `oneof`_ ``action``. + tts (google.cloud.dialogflowcx_v3beta1.types.Action.TTS): + Optional. Text-to-speech action performed by + the agent. + + This field is a member of `oneof`_ ``action``. + stt (google.cloud.dialogflowcx_v3beta1.types.Action.STT): + Optional. Speech-to-text action performed by + the agent. + + This field is a member of `oneof`_ ``action``. + display_name (str): + Output only. The display name of the action. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp of the start of the + agent action. + complete_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp of the completion of + the agent action. + sub_execution_steps (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.Span]): + Optional. The detailed tracing information + for sub execution steps of the action. + status (google.cloud.dialogflowcx_v3beta1.types.Status): + Optional. Output only. The status of the + action. + """ + + class IntentMatch(proto.Message): + r"""Stores metadata of the intent match action. + + Attributes: + matched_intents (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.Action.IntentMatch.MatchedIntent]): + The matched intent. + """ + + class MatchedIntent(proto.Message): + r"""Stores the matched intent, which is the result of the intent + match action. + + Attributes: + intent_id (str): + The ID of the matched intent. + display_name (str): + The display name of the matched intent. + score (float): + The score of the matched intent. + generative_fallback (google.protobuf.struct_pb2.Struct): + The generative fallback response of the + matched intent. + """ + + intent_id: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=2, + ) + score: float = proto.Field( + proto.FLOAT, + number=3, + ) + generative_fallback: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Struct, + ) + + matched_intents: MutableSequence[ + "Action.IntentMatch.MatchedIntent" + ] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Action.IntentMatch.MatchedIntent", + ) + + class FlowStateUpdate(proto.Message): + r"""Stores metadata of the state update action, such as a state + machine execution in flows. + + Attributes: + event_type (str): + The type of the event that triggered the + state update. + page_state (google.cloud.dialogflowcx_v3beta1.types.Action.FlowStateUpdate.PageState): + The updated page and flow state. + updated_parameters (google.protobuf.struct_pb2.Struct): + The updated parameters. + destination (str): + The destination of the transition. Format: + ``projects//locations//agents//flows//pages/`` + or + ``projects//locations//agents//playbooks/``. + function_call (google.cloud.dialogflowcx_v3beta1.types.Action.FlowStateUpdate.FunctionCall): + The function call to execute. + """ + + class PageState(proto.Message): + r"""Stores the state of a page and its flow. + + Attributes: + page (str): + The ID of the page. Format: + ``projects//locations//agents//flows//pages/``. + display_name (str): + The display name of the page. + status (str): + The status of the page. + """ + + page: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=2, + ) + status: str = proto.Field( + proto.STRING, + number=3, + ) + + class FunctionCall(proto.Message): + r"""Stores the metadata of a function call to execute. + + Attributes: + name (str): + The name of the function call. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + event_type: str = proto.Field( + proto.STRING, + number=1, + ) + page_state: "Action.FlowStateUpdate.PageState" = proto.Field( + proto.MESSAGE, + number=2, + message="Action.FlowStateUpdate.PageState", + ) + updated_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Struct, + ) + destination: str = proto.Field( + proto.STRING, + number=4, + ) + function_call: "Action.FlowStateUpdate.FunctionCall" = proto.Field( + proto.MESSAGE, + number=5, + message="Action.FlowStateUpdate.FunctionCall", + ) + + class TTS(proto.Message): + r"""Stores metadata of the Text-to-Speech action.""" + + class STT(proto.Message): + r"""Stores metadata of the Speech-to-Text action.""" + + user_utterance: "UserUtterance" = proto.Field( + proto.MESSAGE, + number=1, + oneof="action", + message="UserUtterance", + ) + event: "Event" = proto.Field( + proto.MESSAGE, + number=7, + oneof="action", + message="Event", + ) + agent_utterance: "AgentUtterance" = proto.Field( + proto.MESSAGE, + number=2, + oneof="action", + message="AgentUtterance", + ) + tool_use: "ToolUse" = proto.Field( + proto.MESSAGE, + number=3, + oneof="action", + message="ToolUse", + ) + llm_call: "LlmCall" = proto.Field( + proto.MESSAGE, + number=14, + oneof="action", + message="LlmCall", + ) + intent_match: IntentMatch = proto.Field( + proto.MESSAGE, + number=17, + oneof="action", + message=IntentMatch, + ) + flow_state_update: FlowStateUpdate = proto.Field( + proto.MESSAGE, + number=18, + oneof="action", + message=FlowStateUpdate, + ) + playbook_invocation: "PlaybookInvocation" = proto.Field( + proto.MESSAGE, + number=4, + oneof="action", + message="PlaybookInvocation", + ) + flow_invocation: "FlowInvocation" = proto.Field( + proto.MESSAGE, + number=5, + oneof="action", + message="FlowInvocation", + ) + playbook_transition: "PlaybookTransition" = proto.Field( + proto.MESSAGE, + number=12, + oneof="action", + message="PlaybookTransition", + ) + flow_transition: "FlowTransition" = proto.Field( + proto.MESSAGE, + number=13, + oneof="action", + message="FlowTransition", + ) + tts: TTS = proto.Field( + proto.MESSAGE, + number=19, + oneof="action", + message=TTS, + ) + stt: STT = proto.Field( + proto.MESSAGE, + number=20, + oneof="action", + message=STT, + ) + display_name: str = proto.Field( + proto.STRING, + number=15, + ) + start_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + complete_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, + ) + sub_execution_steps: MutableSequence["Span"] = proto.RepeatedField( + proto.MESSAGE, + number=11, + message="Span", + ) + status: "Status" = proto.Field( + proto.MESSAGE, + number=16, + message="Status", + ) + + +class UserUtterance(proto.Message): + r"""UserUtterance represents one message sent by the customer. + + Attributes: + text (str): + Required. Message content in text. + audio_tokens (MutableSequence[int]): + Optional. Tokens of the audio input. + audio (bytes): + Optional. Audio input. + """ + + text: str = proto.Field( + proto.STRING, + number=1, + ) + audio_tokens: MutableSequence[int] = proto.RepeatedField( + proto.INT32, + number=2, + ) + audio: bytes = proto.Field( + proto.BYTES, + number=3, + ) + + +class Event(proto.Message): + r"""Event represents the event sent by the customer. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + event (str): + Required. Name of the event. + text (str): + Optional. Unstructured text payload of the + event. + + This field is a member of `oneof`_ ``payload``. + """ + + event: str = proto.Field( + proto.STRING, + number=1, + ) + text: str = proto.Field( + proto.STRING, + number=2, + oneof="payload", + ) + + +class AgentUtterance(proto.Message): + r"""AgentUtterance represents one message sent by the agent. + + Attributes: + text (str): + Required. Message content in text. + require_generation (bool): + Optional. True if the agent utterance needs to be generated + by the LLM. Only used in webhook response to differentiate + from empty text. Revisit whether we need this field or mark + ``text`` as optional when we expose webhook interface to + customer. + """ + + text: str = proto.Field( + proto.STRING, + number=1, + ) + require_generation: bool = proto.Field( + proto.BOOL, + number=2, + ) + + +class ToolUse(proto.Message): + r"""Stores metadata of the invocation of an action supported by a + tool. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + tool (str): + Required. The + [tool][google.cloud.dialogflow.cx.v3beta1.Tool] that should + be used. Format: + ``projects//locations//agents//tools/``. + display_name (str): + Output only. The display name of the tool. + action (str): + Optional. Name of the action to be called + during the tool use. + input_action_parameters (google.protobuf.struct_pb2.Struct): + Optional. A list of input parameters for the + action. + output_action_parameters (google.protobuf.struct_pb2.Struct): + Optional. A list of output parameters + generated by the action. + data_store_tool_trace (google.cloud.dialogflowcx_v3beta1.types.ToolUse.DataStoreToolTrace): + Optional. Data store tool trace. + + This field is a member of `oneof`_ ``ToolTrace``. + webhook_tool_trace (google.cloud.dialogflowcx_v3beta1.types.ToolUse.WebhookToolTrace): + Optional. Webhook tool trace. + + This field is a member of `oneof`_ ``ToolTrace``. + """ + + class DataStoreToolTrace(proto.Message): + r"""The tracing information for the data store tool. + + Attributes: + data_store_connection_signals (google.cloud.dialogflowcx_v3beta1.types.DataStoreConnectionSignals): + Optional. Data store connection feature + output signals. + """ + + data_store_connection_signals: data_store_connection.DataStoreConnectionSignals = proto.Field( + proto.MESSAGE, + number=1, + message=data_store_connection.DataStoreConnectionSignals, + ) + + class WebhookToolTrace(proto.Message): + r"""The tracing information for the webhook tool. + + Attributes: + webhook_tag (str): + Optional. The tag of the webhook. + webhook_uri (str): + Optional. The url of the webhook. + """ + + webhook_tag: str = proto.Field( + proto.STRING, + number=1, + ) + webhook_uri: str = proto.Field( + proto.STRING, + number=2, + ) + + tool: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=8, + ) + action: str = proto.Field( + proto.STRING, + number=2, + ) + input_action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=5, + message=struct_pb2.Struct, + ) + output_action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Struct, + ) + data_store_tool_trace: DataStoreToolTrace = proto.Field( + proto.MESSAGE, + number=7, + oneof="ToolTrace", + message=DataStoreToolTrace, + ) + webhook_tool_trace: WebhookToolTrace = proto.Field( + proto.MESSAGE, + number=9, + oneof="ToolTrace", + message=WebhookToolTrace, + ) + + +class LlmCall(proto.Message): + r"""Stores metadata of the call of an LLM. + + Attributes: + retrieved_examples (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.LlmCall.RetrievedExample]): + A list of relevant examples used for the LLM + prompt. + token_count (google.cloud.dialogflowcx_v3beta1.types.LlmCall.TokenCount): + The token counts of the LLM call. + model (str): + The model of the LLM call. + temperature (float): + The temperature of the LLM call. + """ + + class RetrievedExample(proto.Message): + r"""Relevant example used for the LLM prompt. + + Attributes: + example_id (str): + The id of the example. + example_display_name (str): + The display name of the example. + retrieval_strategy (google.cloud.dialogflowcx_v3beta1.types.RetrievalStrategy): + Retrieval strategy of the example. + matched_retrieval_label (str): + Optional. The matched retrieval label of this + LLM call. + """ + + example_id: str = proto.Field( + proto.STRING, + number=1, + ) + example_display_name: str = proto.Field( + proto.STRING, + number=2, + ) + retrieval_strategy: "RetrievalStrategy" = proto.Field( + proto.ENUM, + number=3, + enum="RetrievalStrategy", + ) + matched_retrieval_label: str = proto.Field( + proto.STRING, + number=14, + ) + + class TokenCount(proto.Message): + r"""Stores token counts of the LLM call. + + Attributes: + total_input_token_count (int): + The total number of tokens used for the input + to the LLM call. + conversation_context_token_count (int): + The number of tokens used for the + conversation history in the prompt. + example_token_count (int): + The number of tokens used for the retrieved + examples in the prompt. + total_output_token_count (int): + The total number of tokens used for the + output of the LLM call. + """ + + total_input_token_count: int = proto.Field( + proto.INT64, + number=1, + ) + conversation_context_token_count: int = proto.Field( + proto.INT64, + number=3, + ) + example_token_count: int = proto.Field( + proto.INT64, + number=4, + ) + total_output_token_count: int = proto.Field( + proto.INT64, + number=5, + ) + + retrieved_examples: MutableSequence[RetrievedExample] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=RetrievedExample, + ) + token_count: TokenCount = proto.Field( + proto.MESSAGE, + number=2, + message=TokenCount, + ) + model: str = proto.Field( + proto.STRING, + number=3, + ) + temperature: float = proto.Field( + proto.FLOAT, + number=4, + ) + + +class PlaybookInvocation(proto.Message): + r"""Stores metadata of the invocation of a child playbook. + Playbook invocation actions enter the child playbook. + + Attributes: + playbook (str): + Required. The unique identifier of the playbook. Format: + ``projects//locations//agents//playbooks/``. + display_name (str): + Output only. The display name of the + playbook. + playbook_input (google.cloud.dialogflowcx_v3beta1.types.PlaybookInput): + Optional. Input of the child playbook + invocation. + playbook_output (google.cloud.dialogflowcx_v3beta1.types.PlaybookOutput): + Optional. Output of the child playbook + invocation. + playbook_state (google.cloud.dialogflowcx_v3beta1.types.OutputState): + Required. Playbook invocation's output state. + """ + + playbook: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=5, + ) + playbook_input: "PlaybookInput" = proto.Field( + proto.MESSAGE, + number=2, + message="PlaybookInput", + ) + playbook_output: "PlaybookOutput" = proto.Field( + proto.MESSAGE, + number=3, + message="PlaybookOutput", + ) + playbook_state: "OutputState" = proto.Field( + proto.ENUM, + number=4, + enum="OutputState", + ) + + +class FlowInvocation(proto.Message): + r"""Stores metadata of the invocation of a child CX flow. Flow + invocation actions enter the child flow. + + Attributes: + flow (str): + Required. The unique identifier of the flow. Format: + ``projects//locations//agents/``. + display_name (str): + Output only. The display name of the flow. + input_action_parameters (google.protobuf.struct_pb2.Struct): + Optional. A list of input parameters for the + flow. + output_action_parameters (google.protobuf.struct_pb2.Struct): + Optional. A list of output parameters + generated by the flow invocation. + flow_state (google.cloud.dialogflowcx_v3beta1.types.OutputState): + Required. Flow invocation's output state. + """ + + flow: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=7, + ) + input_action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=5, + message=struct_pb2.Struct, + ) + output_action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Struct, + ) + flow_state: "OutputState" = proto.Field( + proto.ENUM, + number=4, + enum="OutputState", + ) + + +class PlaybookTransition(proto.Message): + r"""Stores metadata of the transition to another target playbook. + Playbook transition actions exit the caller playbook and enter + the target playbook. + + Attributes: + playbook (str): + Required. The unique identifier of the playbook. Format: + ``projects//locations//agents//playbooks/``. + display_name (str): + Output only. The display name of the + playbook. + input_action_parameters (google.protobuf.struct_pb2.Struct): + A list of input parameters for the action. + """ + + playbook: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=3, + ) + input_action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Struct, + ) + + +class FlowTransition(proto.Message): + r"""Stores metadata of the transition to a target CX flow. Flow + transition actions exit the caller playbook and enter the child + flow. + + Attributes: + flow (str): + Required. The unique identifier of the flow. Format: + ``projects//locations//agents/``. + display_name (str): + Output only. The display name of the flow. + input_action_parameters (google.protobuf.struct_pb2.Struct): + A list of input parameters for the action. + """ + + flow: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=3, + ) + input_action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Struct, + ) + + +class PlaybookInput(proto.Message): + r"""Input of the playbook. + + Attributes: + preceding_conversation_summary (str): + Optional. Summary string of the preceding + conversation for the child playbook invocation. + action_parameters (google.protobuf.struct_pb2.Struct): + Optional. A list of input parameters for the + action. + """ + + preceding_conversation_summary: str = proto.Field( + proto.STRING, + number=1, + ) + action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Struct, + ) + + +class PlaybookOutput(proto.Message): + r"""Output of the playbook. + + Attributes: + execution_summary (str): + Optional. Summary string of the execution + result of the child playbook. + state (google.cloud.dialogflowcx_v3beta1.types.PlaybookOutput.State): + End state of the playbook. + action_parameters (google.protobuf.struct_pb2.Struct): + Optional. A Struct object of output + parameters for the action. + """ + + class State(proto.Enum): + r"""Playbook output state. + + Values: + STATE_UNSPECIFIED (0): + Unspecified state. + OK (1): + Playbook succeeded. + CANCELLED (2): + Playbook cancelled. + FAILED (3): + Playbook failed. + ESCALATED (4): + Playbook failed due to escalation. + """ + _pb_options = {"deprecated": True} + STATE_UNSPECIFIED = 0 + OK = 1 + CANCELLED = 2 + FAILED = 3 + ESCALATED = 4 + + execution_summary: str = proto.Field( + proto.STRING, + number=1, + ) + state: State = proto.Field( + proto.ENUM, + number=2, + enum=State, + ) + action_parameters: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Struct, + ) + + +class Span(proto.Message): + r"""A span represents a sub execution step of an action. + + Attributes: + name (str): + The name of the span. + tags (MutableSequence[str]): + The metadata tags of the span such as span + type. + metrics (MutableSequence[google.cloud.dialogflowcx_v3beta1.types.NamedMetric]): + The unordered collection of metrics in this + span. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Timestamp of the start of the span. + complete_time (google.protobuf.timestamp_pb2.Timestamp): + Timestamp of the completion of the span. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + tags: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + metrics: MutableSequence["NamedMetric"] = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="NamedMetric", + ) + start_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + complete_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + + +class NamedMetric(proto.Message): + r"""A named metric is a metric with name, value and unit. + + Attributes: + name (str): + The name of the metric. + value (google.protobuf.struct_pb2.Value): + The value of the metric. + unit (str): + The unit in which this metric is reported. Follows `The + Unified Code for Units of + Measure `__ standard. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + value: struct_pb2.Value = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) + unit: str = proto.Field( + proto.STRING, + number=3, + ) + + +class Status(proto.Message): + r"""The status of the action. + + Attributes: + exception (google.cloud.dialogflowcx_v3beta1.types.ExceptionDetail): + Optional. The exception thrown during the + execution of the action. + """ + + exception: "ExceptionDetail" = proto.Field( + proto.MESSAGE, + number=1, + message="ExceptionDetail", + ) + + +class ExceptionDetail(proto.Message): + r"""Exception thrown during the execution of an action. + + Attributes: + error_message (str): + Optional. The error message. + """ + + error_message: str = proto.Field( + proto.STRING, + number=1, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/webhook.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/webhook.py index d8dfe51cb8f1..42db248c7b4d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/webhook.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/types/webhook.py @@ -99,9 +99,23 @@ class GenericWebService(proto.Message): The user name for HTTP Basic authentication. password (str): The password for HTTP Basic authentication. + secret_version_for_username_password (str): + Optional. The SecretManager secret version resource storing + the username:password pair for HTTP Basic authentication. + Format: + ``projects/{project}/secrets/{secret}/versions/{version}`` request_headers (MutableMapping[str, str]): The HTTP request headers to send together with webhook requests. + secret_versions_for_request_headers (MutableMapping[str, google.cloud.dialogflowcx_v3beta1.types.Webhook.GenericWebService.SecretVersionHeaderValue]): + Optional. The HTTP request headers to send together with + webhook requests. Header values are stored in SecretManager + secret versions. + + When the same header name is specified in both + ``request_headers`` and + ``secret_versions_for_request_headers``, the value in + ``secret_versions_for_request_headers`` will be used. allowed_ca_certs (MutableSequence[bytes]): Optional. Specifies a list of allowed custom CA certificates (in DER format) for HTTPS verification. This overrides the @@ -217,6 +231,22 @@ class HttpMethod(proto.Enum): PATCH = 6 OPTIONS = 7 + class SecretVersionHeaderValue(proto.Message): + r"""Represents the value of an HTTP header stored in a + SecretManager secret version. + + Attributes: + secret_version (str): + Required. The SecretManager secret version resource storing + the header value. Format: + ``projects/{project}/secrets/{secret}/versions/{version}`` + """ + + secret_version: str = proto.Field( + proto.STRING, + number=1, + ) + class OAuthConfig(proto.Message): r"""Represents configuration of OAuth client credential flow for 3rd party API authentication. @@ -228,6 +258,11 @@ class OAuthConfig(proto.Message): client_secret (str): Optional. The client secret provided by the 3rd party platform. + secret_version_for_client_secret (str): + Optional. The name of the SecretManager secret version + resource storing the client secret. If this field is set, + the ``client_secret`` field will be ignored. Format: + ``projects/{project}/secrets/{secret}/versions/{version}`` token_endpoint (str): Required. The token endpoint provided by the 3rd party platform to exchange an access token. @@ -243,6 +278,10 @@ class OAuthConfig(proto.Message): proto.STRING, number=2, ) + secret_version_for_client_secret: str = proto.Field( + proto.STRING, + number=5, + ) token_endpoint: str = proto.Field( proto.STRING, number=3, @@ -264,11 +303,23 @@ class OAuthConfig(proto.Message): proto.STRING, number=3, ) + secret_version_for_username_password: str = proto.Field( + proto.STRING, + number=19, + ) request_headers: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=4, ) + secret_versions_for_request_headers: MutableMapping[ + str, "Webhook.GenericWebService.SecretVersionHeaderValue" + ] = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=20, + message="Webhook.GenericWebService.SecretVersionHeaderValue", + ) allowed_ca_certs: MutableSequence[bytes] = proto.RepeatedField( proto.BYTES, number=5, diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_export_playbook_async.py b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_export_playbook_async.py new file mode 100644 index 000000000000..fc5b11f9de07 --- /dev/null +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_export_playbook_async.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportPlaybook +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-dialogflow-cx + + +# [START dialogflow_v3beta1_generated_Playbooks_ExportPlaybook_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import dialogflowcx_v3beta1 + + +async def sample_export_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksAsyncClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ExportPlaybookRequest( + name="name_value", + ) + + # Make the request + operation = client.export_playbook(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END dialogflow_v3beta1_generated_Playbooks_ExportPlaybook_async] diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_export_playbook_sync.py b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_export_playbook_sync.py new file mode 100644 index 000000000000..c70cf509538d --- /dev/null +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_export_playbook_sync.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportPlaybook +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-dialogflow-cx + + +# [START dialogflow_v3beta1_generated_Playbooks_ExportPlaybook_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import dialogflowcx_v3beta1 + + +def sample_export_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ExportPlaybookRequest( + name="name_value", + ) + + # Make the request + operation = client.export_playbook(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END dialogflow_v3beta1_generated_Playbooks_ExportPlaybook_sync] diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_import_playbook_async.py b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_import_playbook_async.py new file mode 100644 index 000000000000..7d6a993e92bd --- /dev/null +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_import_playbook_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportPlaybook +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-dialogflow-cx + + +# [START dialogflow_v3beta1_generated_Playbooks_ImportPlaybook_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import dialogflowcx_v3beta1 + + +async def sample_import_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksAsyncClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ImportPlaybookRequest( + playbook_uri="playbook_uri_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_playbook(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END dialogflow_v3beta1_generated_Playbooks_ImportPlaybook_async] diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_import_playbook_sync.py b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_import_playbook_sync.py new file mode 100644 index 000000000000..040a48b7b64f --- /dev/null +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_import_playbook_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportPlaybook +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-dialogflow-cx + + +# [START dialogflow_v3beta1_generated_Playbooks_ImportPlaybook_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import dialogflowcx_v3beta1 + + +def sample_import_playbook(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.ImportPlaybookRequest( + playbook_uri="playbook_uri_value", + parent="parent_value", + ) + + # Make the request + operation = client.import_playbook(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END dialogflow_v3beta1_generated_Playbooks_ImportPlaybook_sync] diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_restore_playbook_version_async.py b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_restore_playbook_version_async.py new file mode 100644 index 000000000000..48d65c990fee --- /dev/null +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_restore_playbook_version_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RestorePlaybookVersion +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-dialogflow-cx + + +# [START dialogflow_v3beta1_generated_Playbooks_RestorePlaybookVersion_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import dialogflowcx_v3beta1 + + +async def sample_restore_playbook_version(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksAsyncClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.RestorePlaybookVersionRequest( + name="name_value", + ) + + # Make the request + response = await client.restore_playbook_version(request=request) + + # Handle the response + print(response) + +# [END dialogflow_v3beta1_generated_Playbooks_RestorePlaybookVersion_async] diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_restore_playbook_version_sync.py b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_restore_playbook_version_sync.py new file mode 100644 index 000000000000..af31013305a2 --- /dev/null +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/dialogflow_v3beta1_generated_playbooks_restore_playbook_version_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RestorePlaybookVersion +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-dialogflow-cx + + +# [START dialogflow_v3beta1_generated_Playbooks_RestorePlaybookVersion_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import dialogflowcx_v3beta1 + + +def sample_restore_playbook_version(): + # Create a client + client = dialogflowcx_v3beta1.PlaybooksClient() + + # Initialize request argument(s) + request = dialogflowcx_v3beta1.RestorePlaybookVersionRequest( + name="name_value", + ) + + # Make the request + response = client.restore_playbook_version(request=request) + + # Handle the response + print(response) + +# [END dialogflow_v3beta1_generated_Playbooks_RestorePlaybookVersion_sync] diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3.json b/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3.json index 140f128144b0..381a0e6e4137 100644 --- a/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3.json +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dialogflow-cx", - "version": "1.43.0" + "version": "0.0.0" }, "snippets": [ { diff --git a/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3beta1.json b/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3beta1.json index b2f78e072d63..170d9db2c40c 100644 --- a/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3beta1.json +++ b/packages/google-cloud-dialogflow-cx/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.cx.v3beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dialogflow-cx", - "version": "1.43.0" + "version": "0.0.0" }, "snippets": [ { @@ -12416,6 +12416,159 @@ ], "title": "dialogflow_v3beta1_generated_playbooks_delete_playbook_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksAsyncClient", + "shortName": "PlaybooksAsyncClient" + }, + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksAsyncClient.export_playbook", + "method": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook", + "service": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "shortName": "Playbooks" + }, + "shortName": "ExportPlaybook" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.dialogflowcx_v3beta1.types.ExportPlaybookRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "export_playbook" + }, + "description": "Sample for ExportPlaybook", + "file": "dialogflow_v3beta1_generated_playbooks_export_playbook_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "dialogflow_v3beta1_generated_Playbooks_ExportPlaybook_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "dialogflow_v3beta1_generated_playbooks_export_playbook_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksClient", + "shortName": "PlaybooksClient" + }, + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksClient.export_playbook", + "method": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks.ExportPlaybook", + "service": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "shortName": "Playbooks" + }, + "shortName": "ExportPlaybook" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.dialogflowcx_v3beta1.types.ExportPlaybookRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "export_playbook" + }, + "description": "Sample for ExportPlaybook", + "file": "dialogflow_v3beta1_generated_playbooks_export_playbook_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "dialogflow_v3beta1_generated_Playbooks_ExportPlaybook_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "dialogflow_v3beta1_generated_playbooks_export_playbook_sync.py" + }, { "canonical": true, "clientMethod": { @@ -12738,6 +12891,159 @@ ], "title": "dialogflow_v3beta1_generated_playbooks_get_playbook_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksAsyncClient", + "shortName": "PlaybooksAsyncClient" + }, + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksAsyncClient.import_playbook", + "method": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook", + "service": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "shortName": "Playbooks" + }, + "shortName": "ImportPlaybook" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.dialogflowcx_v3beta1.types.ImportPlaybookRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "import_playbook" + }, + "description": "Sample for ImportPlaybook", + "file": "dialogflow_v3beta1_generated_playbooks_import_playbook_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "dialogflow_v3beta1_generated_Playbooks_ImportPlaybook_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "dialogflow_v3beta1_generated_playbooks_import_playbook_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksClient", + "shortName": "PlaybooksClient" + }, + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksClient.import_playbook", + "method": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks.ImportPlaybook", + "service": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "shortName": "Playbooks" + }, + "shortName": "ImportPlaybook" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.dialogflowcx_v3beta1.types.ImportPlaybookRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "import_playbook" + }, + "description": "Sample for ImportPlaybook", + "file": "dialogflow_v3beta1_generated_playbooks_import_playbook_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "dialogflow_v3beta1_generated_Playbooks_ImportPlaybook_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "dialogflow_v3beta1_generated_playbooks_import_playbook_sync.py" + }, { "canonical": true, "clientMethod": { @@ -13060,6 +13366,167 @@ ], "title": "dialogflow_v3beta1_generated_playbooks_list_playbooks_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksAsyncClient", + "shortName": "PlaybooksAsyncClient" + }, + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksAsyncClient.restore_playbook_version", + "method": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion", + "service": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "shortName": "Playbooks" + }, + "shortName": "RestorePlaybookVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionResponse", + "shortName": "restore_playbook_version" + }, + "description": "Sample for RestorePlaybookVersion", + "file": "dialogflow_v3beta1_generated_playbooks_restore_playbook_version_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "dialogflow_v3beta1_generated_Playbooks_RestorePlaybookVersion_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "dialogflow_v3beta1_generated_playbooks_restore_playbook_version_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksClient", + "shortName": "PlaybooksClient" + }, + "fullName": "google.cloud.dialogflowcx_v3beta1.PlaybooksClient.restore_playbook_version", + "method": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks.RestorePlaybookVersion", + "service": { + "fullName": "google.cloud.dialogflow.cx.v3beta1.Playbooks", + "shortName": "Playbooks" + }, + "shortName": "RestorePlaybookVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.cloud.dialogflowcx_v3beta1.types.RestorePlaybookVersionResponse", + "shortName": "restore_playbook_version" + }, + "description": "Sample for RestorePlaybookVersion", + "file": "dialogflow_v3beta1_generated_playbooks_restore_playbook_version_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "dialogflow_v3beta1_generated_Playbooks_RestorePlaybookVersion_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "dialogflow_v3beta1_generated_playbooks_restore_playbook_version_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/packages/google-cloud-dialogflow-cx/scripts/fixup_dialogflowcx_v3beta1_keywords.py b/packages/google-cloud-dialogflow-cx/scripts/fixup_dialogflowcx_v3beta1_keywords.py index 2d459f89076d..1513b35a4db1 100644 --- a/packages/google-cloud-dialogflow-cx/scripts/fixup_dialogflowcx_v3beta1_keywords.py +++ b/packages/google-cloud-dialogflow-cx/scripts/fixup_dialogflowcx_v3beta1_keywords.py @@ -87,6 +87,7 @@ class dialogflowcxCallTransformer(cst.CSTTransformer): 'export_entity_types': ('parent', 'entity_types', 'entity_types_uri', 'entity_types_content_inline', 'data_format', 'language_code', ), 'export_flow': ('name', 'flow_uri', 'include_referenced_flows', ), 'export_intents': ('parent', 'intents', 'intents_uri', 'intents_content_inline', 'data_format', ), + 'export_playbook': ('name', 'playbook_uri', 'data_format', ), 'export_test_cases': ('parent', 'gcs_uri', 'data_format', 'filter', ), 'export_tools': ('parent', 'tools', 'tools_uri', 'tools_content_inline', 'data_format', ), 'fulfill_intent': ('match_intent_request', 'match', 'output_audio_config', ), @@ -119,6 +120,7 @@ class dialogflowcxCallTransformer(cst.CSTTransformer): 'import_entity_types': ('parent', 'merge_option', 'entity_types_uri', 'entity_types_content', 'target_entity_type', ), 'import_flow': ('parent', 'flow_uri', 'flow_content', 'import_option', 'flow_import_strategy', ), 'import_intents': ('parent', 'intents_uri', 'intents_content', 'merge_option', ), + 'import_playbook': ('parent', 'playbook_uri', 'playbook_content', 'import_strategy', ), 'import_test_cases': ('parent', 'gcs_uri', 'content', ), 'list_agents': ('parent', 'page_size', 'page_token', ), 'list_changelogs': ('parent', 'filter', 'page_size', 'page_token', ), @@ -148,6 +150,7 @@ class dialogflowcxCallTransformer(cst.CSTTransformer): 'lookup_environment_history': ('name', 'page_size', 'page_token', ), 'match_intent': ('session', 'query_input', 'query_params', 'persist_parameter_changes', ), 'restore_agent': ('name', 'agent_uri', 'agent_content', 'git_source', 'restore_option', ), + 'restore_playbook_version': ('name', ), 'restore_tool_version': ('name', ), 'run_continuous_test': ('environment', ), 'run_test_case': ('name', 'environment', ), diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py index 1cfc22851757..67bde841bb97 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py @@ -9084,6 +9084,7 @@ def test_update_generative_settings_rest_call_success(request_type): "banned_phrases": [ {"text": "text_value", "language_code": "language_code_value"} ], + "prompt_security_settings": {"enable_prompt_security": True}, }, "knowledge_connector_settings": { "business": "business_value", @@ -9097,6 +9098,11 @@ def test_update_generative_settings_rest_call_success(request_type): "llm_model_settings": { "model": "model_value", "prompt_text": "prompt_text_value", + "parameters": { + "temperature": 0.1198, + "input_token_limit": 1, + "output_token_limit": 1, + }, }, } # The version of a generated dependency at test runtime may differ from the version used during generation. diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py index a6a05a143c12..f2e129b6f6a8 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py @@ -4690,11 +4690,42 @@ def test_parse_flow_path(): assert expected == actual -def test_intent_path(): +def test_generator_path(): project = "squid" location = "clam" agent = "whelk" - intent = "octopus" + generator = "octopus" + expected = "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + actual = ConversationHistoryClient.generator_path( + project, location, agent, generator + ) + assert expected == actual + + +def test_parse_generator_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "agent": "cuttlefish", + "generator": "mussel", + } + path = ConversationHistoryClient.generator_path(**expected) + + # Check that the path construction is reversible. + actual = ConversationHistoryClient.parse_generator_path(path) + assert expected == actual + + +def test_intent_path(): + project = "winkle" + location = "nautilus" + agent = "scallop" + intent = "abalone" expected = "projects/{project}/locations/{location}/agents/{agent}/intents/{intent}".format( project=project, location=location, @@ -4707,10 +4738,10 @@ def test_intent_path(): def test_parse_intent_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "agent": "cuttlefish", - "intent": "mussel", + "project": "squid", + "location": "clam", + "agent": "whelk", + "intent": "octopus", } path = ConversationHistoryClient.intent_path(**expected) @@ -4720,11 +4751,11 @@ def test_parse_intent_path(): def test_page_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - flow = "abalone" - page = "squid" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + flow = "mussel" + page = "winkle" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/pages/{page}".format( project=project, location=location, @@ -4738,11 +4769,11 @@ def test_page_path(): def test_parse_page_path(): expected = { - "project": "clam", - "location": "whelk", - "agent": "octopus", - "flow": "oyster", - "page": "nudibranch", + "project": "nautilus", + "location": "scallop", + "agent": "abalone", + "flow": "squid", + "page": "clam", } path = ConversationHistoryClient.page_path(**expected) @@ -4752,10 +4783,10 @@ def test_parse_page_path(): def test_playbook_path(): - project = "cuttlefish" - location = "mussel" - agent = "winkle" - playbook = "nautilus" + project = "whelk" + location = "octopus" + agent = "oyster" + playbook = "nudibranch" expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}".format( project=project, location=location, @@ -4768,10 +4799,10 @@ def test_playbook_path(): def test_parse_playbook_path(): expected = { - "project": "scallop", - "location": "abalone", - "agent": "squid", - "playbook": "clam", + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "playbook": "nautilus", } path = ConversationHistoryClient.playbook_path(**expected) @@ -4780,11 +4811,37 @@ def test_parse_playbook_path(): assert expected == actual +def test_secret_version_path(): + project = "scallop" + secret = "abalone" + version = "squid" + expected = "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + actual = ConversationHistoryClient.secret_version_path(project, secret, version) + assert expected == actual + + +def test_parse_secret_version_path(): + expected = { + "project": "clam", + "secret": "whelk", + "version": "octopus", + } + path = ConversationHistoryClient.secret_version_path(**expected) + + # Check that the path construction is reversible. + actual = ConversationHistoryClient.parse_secret_version_path(path) + assert expected == actual + + def test_service_path(): - project = "whelk" - location = "octopus" - namespace = "oyster" - service = "nudibranch" + project = "oyster" + location = "nudibranch" + namespace = "cuttlefish" + service = "mussel" expected = "projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}".format( project=project, location=location, @@ -4799,10 +4856,10 @@ def test_service_path(): def test_parse_service_path(): expected = { - "project": "cuttlefish", - "location": "mussel", - "namespace": "winkle", - "service": "nautilus", + "project": "winkle", + "location": "nautilus", + "namespace": "scallop", + "service": "abalone", } path = ConversationHistoryClient.service_path(**expected) @@ -4812,10 +4869,10 @@ def test_parse_service_path(): def test_session_path(): - project = "scallop" - location = "abalone" - agent = "squid" - session = "clam" + project = "squid" + location = "clam" + agent = "whelk" + session = "octopus" expected = "projects/{project}/locations/{location}/agents/{agent}/sessions/{session}".format( project=project, location=location, @@ -4828,10 +4885,10 @@ def test_session_path(): def test_parse_session_path(): expected = { - "project": "whelk", - "location": "octopus", - "agent": "oyster", - "session": "nudibranch", + "project": "oyster", + "location": "nudibranch", + "agent": "cuttlefish", + "session": "mussel", } path = ConversationHistoryClient.session_path(**expected) @@ -4841,11 +4898,11 @@ def test_parse_session_path(): def test_session_entity_type_path(): - project = "cuttlefish" - location = "mussel" - agent = "winkle" - session = "nautilus" - entity_type = "scallop" + project = "winkle" + location = "nautilus" + agent = "scallop" + session = "abalone" + entity_type = "squid" expected = "projects/{project}/locations/{location}/agents/{agent}/sessions/{session}/entityTypes/{entity_type}".format( project=project, location=location, @@ -4861,11 +4918,11 @@ def test_session_entity_type_path(): def test_parse_session_entity_type_path(): expected = { - "project": "abalone", - "location": "squid", - "agent": "clam", - "session": "whelk", - "entity_type": "octopus", + "project": "clam", + "location": "whelk", + "agent": "octopus", + "session": "oyster", + "entity_type": "nudibranch", } path = ConversationHistoryClient.session_entity_type_path(**expected) @@ -4875,10 +4932,10 @@ def test_parse_session_entity_type_path(): def test_test_case_path(): - project = "oyster" - location = "nudibranch" - agent = "cuttlefish" - test_case = "mussel" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + test_case = "nautilus" expected = "projects/{project}/locations/{location}/agents/{agent}/testCases/{test_case}".format( project=project, location=location, @@ -4893,10 +4950,10 @@ def test_test_case_path(): def test_parse_test_case_path(): expected = { - "project": "winkle", - "location": "nautilus", - "agent": "scallop", - "test_case": "abalone", + "project": "scallop", + "location": "abalone", + "agent": "squid", + "test_case": "clam", } path = ConversationHistoryClient.test_case_path(**expected) @@ -4906,10 +4963,10 @@ def test_parse_test_case_path(): def test_tool_path(): - project = "squid" - location = "clam" - agent = "whelk" - tool = "octopus" + project = "whelk" + location = "octopus" + agent = "oyster" + tool = "nudibranch" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -4924,10 +4981,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "agent": "cuttlefish", - "tool": "mussel", + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "tool": "nautilus", } path = ConversationHistoryClient.tool_path(**expected) @@ -4937,11 +4994,11 @@ def test_parse_tool_path(): def test_transition_route_group_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - flow = "abalone" - transition_route_group = "squid" + project = "scallop" + location = "abalone" + agent = "squid" + flow = "clam" + transition_route_group = "whelk" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/transitionRouteGroups/{transition_route_group}".format( project=project, location=location, @@ -4957,11 +5014,11 @@ def test_transition_route_group_path(): def test_parse_transition_route_group_path(): expected = { - "project": "clam", - "location": "whelk", - "agent": "octopus", - "flow": "oyster", - "transition_route_group": "nudibranch", + "project": "octopus", + "location": "oyster", + "agent": "nudibranch", + "flow": "cuttlefish", + "transition_route_group": "mussel", } path = ConversationHistoryClient.transition_route_group_path(**expected) @@ -4971,11 +5028,11 @@ def test_parse_transition_route_group_path(): def test_version_path(): - project = "cuttlefish" - location = "mussel" - agent = "winkle" - flow = "nautilus" - version = "scallop" + project = "winkle" + location = "nautilus" + agent = "scallop" + flow = "abalone" + version = "squid" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/versions/{version}".format( project=project, location=location, @@ -4991,11 +5048,11 @@ def test_version_path(): def test_parse_version_path(): expected = { - "project": "abalone", - "location": "squid", - "agent": "clam", - "flow": "whelk", - "version": "octopus", + "project": "clam", + "location": "whelk", + "agent": "octopus", + "flow": "oyster", + "version": "nudibranch", } path = ConversationHistoryClient.version_path(**expected) @@ -5005,10 +5062,10 @@ def test_parse_version_path(): def test_webhook_path(): - project = "oyster" - location = "nudibranch" - agent = "cuttlefish" - webhook = "mussel" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + webhook = "nautilus" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -5021,10 +5078,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "winkle", - "location": "nautilus", - "agent": "scallop", - "webhook": "abalone", + "project": "scallop", + "location": "abalone", + "agent": "squid", + "webhook": "clam", } path = ConversationHistoryClient.webhook_path(**expected) @@ -5034,7 +5091,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "squid" + billing_account = "whelk" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -5044,7 +5101,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "clam", + "billing_account": "octopus", } path = ConversationHistoryClient.common_billing_account_path(**expected) @@ -5054,7 +5111,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "whelk" + folder = "oyster" expected = "folders/{folder}".format( folder=folder, ) @@ -5064,7 +5121,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "octopus", + "folder": "nudibranch", } path = ConversationHistoryClient.common_folder_path(**expected) @@ -5074,7 +5131,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "oyster" + organization = "cuttlefish" expected = "organizations/{organization}".format( organization=organization, ) @@ -5084,7 +5141,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nudibranch", + "organization": "mussel", } path = ConversationHistoryClient.common_organization_path(**expected) @@ -5094,7 +5151,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "cuttlefish" + project = "winkle" expected = "projects/{project}".format( project=project, ) @@ -5104,7 +5161,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "mussel", + "project": "nautilus", } path = ConversationHistoryClient.common_project_path(**expected) @@ -5114,8 +5171,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "scallop" + location = "abalone" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -5126,8 +5183,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "squid", + "location": "clam", } path = ConversationHistoryClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py index e10e67849ab3..eb83bd0bdada 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py @@ -7317,7 +7317,9 @@ def test_create_environment_rest_call_success(request_type): "uri": "uri_value", "username": "username_value", "password": "password_value", + "secret_version_for_username_password": "secret_version_for_username_password_value", "request_headers": {}, + "secret_versions_for_request_headers": {}, "allowed_ca_certs": [ b"allowed_ca_certs_blob1", b"allowed_ca_certs_blob2", @@ -7325,6 +7327,7 @@ def test_create_environment_rest_call_success(request_type): "oauth_config": { "client_id": "client_id_value", "client_secret": "client_secret_value", + "secret_version_for_client_secret": "secret_version_for_client_secret_value", "token_endpoint": "token_endpoint_value", "scopes": ["scopes_value1", "scopes_value2"], }, @@ -7562,7 +7565,9 @@ def test_update_environment_rest_call_success(request_type): "uri": "uri_value", "username": "username_value", "password": "password_value", + "secret_version_for_username_password": "secret_version_for_username_password_value", "request_headers": {}, + "secret_versions_for_request_headers": {}, "allowed_ca_certs": [ b"allowed_ca_certs_blob1", b"allowed_ca_certs_blob2", @@ -7570,6 +7575,7 @@ def test_update_environment_rest_call_success(request_type): "oauth_config": { "client_id": "client_id_value", "client_secret": "client_secret_value", + "secret_version_for_client_secret": "secret_version_for_client_secret_value", "token_endpoint": "token_endpoint_value", "scopes": ["scopes_value1", "scopes_value2"], }, @@ -9462,11 +9468,37 @@ def test_parse_environment_path(): assert expected == actual -def test_service_path(): +def test_secret_version_path(): project = "cuttlefish" - location = "mussel" - namespace = "winkle" - service = "nautilus" + secret = "mussel" + version = "winkle" + expected = "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + actual = EnvironmentsClient.secret_version_path(project, secret, version) + assert expected == actual + + +def test_parse_secret_version_path(): + expected = { + "project": "nautilus", + "secret": "scallop", + "version": "abalone", + } + path = EnvironmentsClient.secret_version_path(**expected) + + # Check that the path construction is reversible. + actual = EnvironmentsClient.parse_secret_version_path(path) + assert expected == actual + + +def test_service_path(): + project = "squid" + location = "clam" + namespace = "whelk" + service = "octopus" expected = "projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}".format( project=project, location=location, @@ -9479,10 +9511,10 @@ def test_service_path(): def test_parse_service_path(): expected = { - "project": "scallop", - "location": "abalone", - "namespace": "squid", - "service": "clam", + "project": "oyster", + "location": "nudibranch", + "namespace": "cuttlefish", + "service": "mussel", } path = EnvironmentsClient.service_path(**expected) @@ -9492,10 +9524,10 @@ def test_parse_service_path(): def test_test_case_path(): - project = "whelk" - location = "octopus" - agent = "oyster" - test_case = "nudibranch" + project = "winkle" + location = "nautilus" + agent = "scallop" + test_case = "abalone" expected = "projects/{project}/locations/{location}/agents/{agent}/testCases/{test_case}".format( project=project, location=location, @@ -9508,10 +9540,10 @@ def test_test_case_path(): def test_parse_test_case_path(): expected = { - "project": "cuttlefish", - "location": "mussel", - "agent": "winkle", - "test_case": "nautilus", + "project": "squid", + "location": "clam", + "agent": "whelk", + "test_case": "octopus", } path = EnvironmentsClient.test_case_path(**expected) @@ -9521,11 +9553,11 @@ def test_parse_test_case_path(): def test_test_case_result_path(): - project = "scallop" - location = "abalone" - agent = "squid" - test_case = "clam" - result = "whelk" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + test_case = "mussel" + result = "winkle" expected = "projects/{project}/locations/{location}/agents/{agent}/testCases/{test_case}/results/{result}".format( project=project, location=location, @@ -9541,11 +9573,11 @@ def test_test_case_result_path(): def test_parse_test_case_result_path(): expected = { - "project": "octopus", - "location": "oyster", - "agent": "nudibranch", - "test_case": "cuttlefish", - "result": "mussel", + "project": "nautilus", + "location": "scallop", + "agent": "abalone", + "test_case": "squid", + "result": "clam", } path = EnvironmentsClient.test_case_result_path(**expected) @@ -9555,11 +9587,11 @@ def test_parse_test_case_result_path(): def test_version_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - flow = "abalone" - version = "squid" + project = "whelk" + location = "octopus" + agent = "oyster" + flow = "nudibranch" + version = "cuttlefish" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/versions/{version}".format( project=project, location=location, @@ -9573,11 +9605,11 @@ def test_version_path(): def test_parse_version_path(): expected = { - "project": "clam", - "location": "whelk", - "agent": "octopus", - "flow": "oyster", - "version": "nudibranch", + "project": "mussel", + "location": "winkle", + "agent": "nautilus", + "flow": "scallop", + "version": "abalone", } path = EnvironmentsClient.version_path(**expected) @@ -9587,10 +9619,10 @@ def test_parse_version_path(): def test_webhook_path(): - project = "cuttlefish" - location = "mussel" - agent = "winkle" - webhook = "nautilus" + project = "squid" + location = "clam" + agent = "whelk" + webhook = "octopus" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -9603,10 +9635,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "scallop", - "location": "abalone", - "agent": "squid", - "webhook": "clam", + "project": "oyster", + "location": "nudibranch", + "agent": "cuttlefish", + "webhook": "mussel", } path = EnvironmentsClient.webhook_path(**expected) @@ -9616,7 +9648,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "whelk" + billing_account = "winkle" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -9626,7 +9658,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "octopus", + "billing_account": "nautilus", } path = EnvironmentsClient.common_billing_account_path(**expected) @@ -9636,7 +9668,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "oyster" + folder = "scallop" expected = "folders/{folder}".format( folder=folder, ) @@ -9646,7 +9678,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "nudibranch", + "folder": "abalone", } path = EnvironmentsClient.common_folder_path(**expected) @@ -9656,7 +9688,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "cuttlefish" + organization = "squid" expected = "organizations/{organization}".format( organization=organization, ) @@ -9666,7 +9698,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "mussel", + "organization": "clam", } path = EnvironmentsClient.common_organization_path(**expected) @@ -9676,7 +9708,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "winkle" + project = "whelk" expected = "projects/{project}".format( project=project, ) @@ -9686,7 +9718,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "nautilus", + "project": "octopus", } path = EnvironmentsClient.common_project_path(**expected) @@ -9696,8 +9728,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "scallop" - location = "abalone" + project = "oyster" + location = "nudibranch" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -9708,8 +9740,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "squid", - "location": "clam", + "project": "cuttlefish", + "location": "mussel", } path = EnvironmentsClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py index fd0932cb75b8..09c24d019d1f 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py @@ -63,8 +63,10 @@ pagers, transports, ) +from google.cloud.dialogflowcx_v3beta1.types import data_store_connection from google.cloud.dialogflowcx_v3beta1.types import example from google.cloud.dialogflowcx_v3beta1.types import example as gcdc_example +from google.cloud.dialogflowcx_v3beta1.types import trace CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -1088,7 +1090,7 @@ def test_create_example(request_type, transport: str = "grpc"): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) response = client.create_example(request) @@ -1105,7 +1107,7 @@ def test_create_example(request_type, transport: str = "grpc"): assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == gcdc_example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -1236,7 +1238,7 @@ async def test_create_example_async( display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) ) @@ -1254,7 +1256,7 @@ async def test_create_example_async( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == gcdc_example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -2273,7 +2275,7 @@ def test_get_example(request_type, transport: str = "grpc"): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) response = client.get_example(request) @@ -2290,7 +2292,7 @@ def test_get_example(request_type, transport: str = "grpc"): assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -2421,7 +2423,7 @@ async def test_get_example_async( display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) ) @@ -2439,7 +2441,7 @@ async def test_get_example_async( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -2612,7 +2614,7 @@ def test_update_example(request_type, transport: str = "grpc"): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) response = client.update_example(request) @@ -2629,7 +2631,7 @@ def test_update_example(request_type, transport: str = "grpc"): assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == gcdc_example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -2756,7 +2758,7 @@ async def test_update_example_async( display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) ) @@ -2774,7 +2776,7 @@ async def test_update_example_async( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == gcdc_example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -4161,7 +4163,7 @@ async def test_create_example_empty_call_grpc_asyncio(): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) ) @@ -4243,7 +4245,7 @@ async def test_get_example_empty_call_grpc_asyncio(): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) ) @@ -4275,7 +4277,7 @@ async def test_update_example_empty_call_grpc_asyncio(): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) ) @@ -4347,18 +4349,106 @@ def test_create_example_rest_call_success(request_type): }, "playbook_output": { "execution_summary": "execution_summary_value", + "state": 1, "action_parameters": {}, }, "actions": [ { - "user_utterance": {"text": "text_value"}, - "agent_utterance": {"text": "text_value"}, + "user_utterance": { + "text": "text_value", + "audio_tokens": [1286, 1287], + "audio": b"audio_blob", + }, + "event": {"event": "event_value", "text": "text_value"}, + "agent_utterance": {"text": "text_value", "require_generation": True}, "tool_use": { "tool": "tool_value", "display_name": "display_name_value", "action": "action_value", "input_action_parameters": {}, "output_action_parameters": {}, + "data_store_tool_trace": { + "data_store_connection_signals": { + "rewriter_model_call_signals": { + "rendered_prompt": "rendered_prompt_value", + "model_output": "model_output_value", + "model": "model_value", + }, + "rewritten_query": "rewritten_query_value", + "search_snippets": [ + { + "document_title": "document_title_value", + "document_uri": "document_uri_value", + "text": "text_value", + "metadata": {}, + } + ], + "answer_generation_model_call_signals": { + "rendered_prompt": "rendered_prompt_value", + "model_output": "model_output_value", + "model": "model_value", + }, + "answer": "answer_value", + "answer_parts": [ + { + "text": "text_value", + "supporting_indices": [1946, 1947], + } + ], + "cited_snippets": [ + {"search_snippet": {}, "snippet_index": 1402} + ], + "grounding_signals": {"decision": 1, "score": 1}, + "safety_signals": { + "decision": 1, + "banned_phrase_match": 1, + "matched_banned_phrase": "matched_banned_phrase_value", + }, + } + }, + "webhook_tool_trace": { + "webhook_tag": "webhook_tag_value", + "webhook_uri": "webhook_uri_value", + }, + }, + "llm_call": { + "retrieved_examples": [ + { + "example_id": "example_id_value", + "example_display_name": "example_display_name_value", + "retrieval_strategy": 1, + "matched_retrieval_label": "matched_retrieval_label_value", + } + ], + "token_count": { + "total_input_token_count": 2491, + "conversation_context_token_count": 3463, + "example_token_count": 2036, + "total_output_token_count": 2620, + }, + "model": "model_value", + "temperature": 0.1198, + }, + "intent_match": { + "matched_intents": [ + { + "intent_id": "intent_id_value", + "display_name": "display_name_value", + "score": 0.54, + "generative_fallback": {}, + } + ] + }, + "flow_state_update": { + "event_type": "event_type_value", + "page_state": { + "page": "page_value", + "display_name": "display_name_value", + "status": "status_value", + }, + "updated_parameters": {}, + "destination": "destination_value", + "function_call": {"name": "name_value"}, }, "playbook_invocation": { "playbook": "playbook_value", @@ -4374,12 +4464,50 @@ def test_create_example_rest_call_success(request_type): "output_action_parameters": {}, "flow_state": 1, }, + "playbook_transition": { + "playbook": "playbook_value", + "display_name": "display_name_value", + "input_action_parameters": {}, + }, + "flow_transition": { + "flow": "flow_value", + "display_name": "display_name_value", + "input_action_parameters": {}, + }, + "tts": {}, + "stt": {}, + "display_name": "display_name_value", + "start_time": {"seconds": 751, "nanos": 543}, + "complete_time": {}, + "sub_execution_steps": [ + { + "name": "name_value", + "tags": ["tags_value1", "tags_value2"], + "metrics": [ + { + "name": "name_value", + "value": { + "null_value": 0, + "number_value": 0.1285, + "string_value": "string_value_value", + "bool_value": True, + "struct_value": {}, + "list_value": {"values": {}}, + }, + "unit": "unit_value", + } + ], + "start_time": {}, + "complete_time": {}, + } + ], + "status": {"exception": {"error_message": "error_message_value"}}, } ], "display_name": "display_name_value", "description": "description_value", "token_count": 1193, - "create_time": {"seconds": 751, "nanos": 543}, + "create_time": {}, "update_time": {}, "conversation_state": 1, "language_code": "language_code_value", @@ -4461,7 +4589,7 @@ def get_message_fields(field): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) @@ -4483,7 +4611,7 @@ def get_message_fields(field): assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == gcdc_example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -4832,7 +4960,7 @@ def test_get_example_rest_call_success(request_type): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) @@ -4854,7 +4982,7 @@ def test_get_example_rest_call_success(request_type): assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" @@ -4971,18 +5099,106 @@ def test_update_example_rest_call_success(request_type): }, "playbook_output": { "execution_summary": "execution_summary_value", + "state": 1, "action_parameters": {}, }, "actions": [ { - "user_utterance": {"text": "text_value"}, - "agent_utterance": {"text": "text_value"}, + "user_utterance": { + "text": "text_value", + "audio_tokens": [1286, 1287], + "audio": b"audio_blob", + }, + "event": {"event": "event_value", "text": "text_value"}, + "agent_utterance": {"text": "text_value", "require_generation": True}, "tool_use": { "tool": "tool_value", "display_name": "display_name_value", "action": "action_value", "input_action_parameters": {}, "output_action_parameters": {}, + "data_store_tool_trace": { + "data_store_connection_signals": { + "rewriter_model_call_signals": { + "rendered_prompt": "rendered_prompt_value", + "model_output": "model_output_value", + "model": "model_value", + }, + "rewritten_query": "rewritten_query_value", + "search_snippets": [ + { + "document_title": "document_title_value", + "document_uri": "document_uri_value", + "text": "text_value", + "metadata": {}, + } + ], + "answer_generation_model_call_signals": { + "rendered_prompt": "rendered_prompt_value", + "model_output": "model_output_value", + "model": "model_value", + }, + "answer": "answer_value", + "answer_parts": [ + { + "text": "text_value", + "supporting_indices": [1946, 1947], + } + ], + "cited_snippets": [ + {"search_snippet": {}, "snippet_index": 1402} + ], + "grounding_signals": {"decision": 1, "score": 1}, + "safety_signals": { + "decision": 1, + "banned_phrase_match": 1, + "matched_banned_phrase": "matched_banned_phrase_value", + }, + } + }, + "webhook_tool_trace": { + "webhook_tag": "webhook_tag_value", + "webhook_uri": "webhook_uri_value", + }, + }, + "llm_call": { + "retrieved_examples": [ + { + "example_id": "example_id_value", + "example_display_name": "example_display_name_value", + "retrieval_strategy": 1, + "matched_retrieval_label": "matched_retrieval_label_value", + } + ], + "token_count": { + "total_input_token_count": 2491, + "conversation_context_token_count": 3463, + "example_token_count": 2036, + "total_output_token_count": 2620, + }, + "model": "model_value", + "temperature": 0.1198, + }, + "intent_match": { + "matched_intents": [ + { + "intent_id": "intent_id_value", + "display_name": "display_name_value", + "score": 0.54, + "generative_fallback": {}, + } + ] + }, + "flow_state_update": { + "event_type": "event_type_value", + "page_state": { + "page": "page_value", + "display_name": "display_name_value", + "status": "status_value", + }, + "updated_parameters": {}, + "destination": "destination_value", + "function_call": {"name": "name_value"}, }, "playbook_invocation": { "playbook": "playbook_value", @@ -4998,12 +5214,50 @@ def test_update_example_rest_call_success(request_type): "output_action_parameters": {}, "flow_state": 1, }, + "playbook_transition": { + "playbook": "playbook_value", + "display_name": "display_name_value", + "input_action_parameters": {}, + }, + "flow_transition": { + "flow": "flow_value", + "display_name": "display_name_value", + "input_action_parameters": {}, + }, + "tts": {}, + "stt": {}, + "display_name": "display_name_value", + "start_time": {"seconds": 751, "nanos": 543}, + "complete_time": {}, + "sub_execution_steps": [ + { + "name": "name_value", + "tags": ["tags_value1", "tags_value2"], + "metrics": [ + { + "name": "name_value", + "value": { + "null_value": 0, + "number_value": 0.1285, + "string_value": "string_value_value", + "bool_value": True, + "struct_value": {}, + "list_value": {"values": {}}, + }, + "unit": "unit_value", + } + ], + "start_time": {}, + "complete_time": {}, + } + ], + "status": {"exception": {"error_message": "error_message_value"}}, } ], "display_name": "display_name_value", "description": "description_value", "token_count": 1193, - "create_time": {"seconds": 751, "nanos": 543}, + "create_time": {}, "update_time": {}, "conversation_state": 1, "language_code": "language_code_value", @@ -5085,7 +5339,7 @@ def get_message_fields(field): display_name="display_name_value", description="description_value", token_count=1193, - conversation_state=gcdc_example.OutputState.OUTPUT_STATE_OK, + conversation_state=trace.OutputState.OUTPUT_STATE_OK, language_code="language_code_value", ) @@ -5107,7 +5361,7 @@ def get_message_fields(field): assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.token_count == 1193 - assert response.conversation_state == gcdc_example.OutputState.OUTPUT_STATE_OK + assert response.conversation_state == trace.OutputState.OUTPUT_STATE_OK assert response.language_code == "language_code_value" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py index 4b18c1f4dcd7..4890b8029a42 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py @@ -83,6 +83,7 @@ gcs, import_strategy, page, + parameter_definition, response_message, tool_call, validation_message, @@ -6800,6 +6801,13 @@ def test_create_flow_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "target_page": "target_page_value", "target_flow": "target_flow_value", @@ -6838,6 +6846,21 @@ def test_create_flow_rest_call_success(request_type): } ], }, + "input_parameter_definitions": [ + { + "name": "name_value", + "type_": 1, + "type_schema": { + "inline_schema": {"type_": 1, "items": {}}, + "schema_reference": { + "tool": "tool_value", + "schema": "schema_value", + }, + }, + "description": "description_value", + } + ], + "output_parameter_definitions": {}, "multi_language_settings": { "enable_multi_language_detection": True, "supported_response_language_codes": [ @@ -7513,6 +7536,13 @@ def test_update_flow_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "target_page": "target_page_value", "target_flow": "target_flow_value", @@ -7551,6 +7581,21 @@ def test_update_flow_rest_call_success(request_type): } ], }, + "input_parameter_definitions": [ + { + "name": "name_value", + "type_": 1, + "type_schema": { + "inline_schema": {"type_": 1, "items": {}}, + "schema_reference": { + "tool": "tool_value", + "schema": "schema_value", + }, + }, + "description": "description_value", + } + ], + "output_parameter_definitions": {}, "multi_language_settings": { "enable_multi_language_detection": True, "supported_response_language_codes": [ @@ -9426,11 +9471,40 @@ def test_parse_flow_validation_result_path(): assert expected == actual -def test_intent_path(): +def test_generator_path(): project = "oyster" location = "nudibranch" agent = "cuttlefish" - intent = "mussel" + generator = "mussel" + expected = "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + actual = FlowsClient.generator_path(project, location, agent, generator) + assert expected == actual + + +def test_parse_generator_path(): + expected = { + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "generator": "abalone", + } + path = FlowsClient.generator_path(**expected) + + # Check that the path construction is reversible. + actual = FlowsClient.parse_generator_path(path) + assert expected == actual + + +def test_intent_path(): + project = "squid" + location = "clam" + agent = "whelk" + intent = "octopus" expected = "projects/{project}/locations/{location}/agents/{agent}/intents/{intent}".format( project=project, location=location, @@ -9443,10 +9517,10 @@ def test_intent_path(): def test_parse_intent_path(): expected = { - "project": "winkle", - "location": "nautilus", - "agent": "scallop", - "intent": "abalone", + "project": "oyster", + "location": "nudibranch", + "agent": "cuttlefish", + "intent": "mussel", } path = FlowsClient.intent_path(**expected) @@ -9456,11 +9530,11 @@ def test_parse_intent_path(): def test_page_path(): - project = "squid" - location = "clam" - agent = "whelk" - flow = "octopus" - page = "oyster" + project = "winkle" + location = "nautilus" + agent = "scallop" + flow = "abalone" + page = "squid" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/pages/{page}".format( project=project, location=location, @@ -9474,11 +9548,11 @@ def test_page_path(): def test_parse_page_path(): expected = { - "project": "nudibranch", - "location": "cuttlefish", - "agent": "mussel", - "flow": "winkle", - "page": "nautilus", + "project": "clam", + "location": "whelk", + "agent": "octopus", + "flow": "oyster", + "page": "nudibranch", } path = FlowsClient.page_path(**expected) @@ -9488,10 +9562,10 @@ def test_parse_page_path(): def test_playbook_path(): - project = "scallop" - location = "abalone" - agent = "squid" - playbook = "clam" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + playbook = "nautilus" expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}".format( project=project, location=location, @@ -9504,10 +9578,10 @@ def test_playbook_path(): def test_parse_playbook_path(): expected = { - "project": "whelk", - "location": "octopus", - "agent": "oyster", - "playbook": "nudibranch", + "project": "scallop", + "location": "abalone", + "agent": "squid", + "playbook": "clam", } path = FlowsClient.playbook_path(**expected) @@ -9517,10 +9591,10 @@ def test_parse_playbook_path(): def test_tool_path(): - project = "cuttlefish" - location = "mussel" - agent = "winkle" - tool = "nautilus" + project = "whelk" + location = "octopus" + agent = "oyster" + tool = "nudibranch" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -9535,10 +9609,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "scallop", - "location": "abalone", - "agent": "squid", - "tool": "clam", + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "tool": "nautilus", } path = FlowsClient.tool_path(**expected) @@ -9548,11 +9622,11 @@ def test_parse_tool_path(): def test_transition_route_group_path(): - project = "whelk" - location = "octopus" - agent = "oyster" - flow = "nudibranch" - transition_route_group = "cuttlefish" + project = "scallop" + location = "abalone" + agent = "squid" + flow = "clam" + transition_route_group = "whelk" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/transitionRouteGroups/{transition_route_group}".format( project=project, location=location, @@ -9568,11 +9642,11 @@ def test_transition_route_group_path(): def test_parse_transition_route_group_path(): expected = { - "project": "mussel", - "location": "winkle", - "agent": "nautilus", - "flow": "scallop", - "transition_route_group": "abalone", + "project": "octopus", + "location": "oyster", + "agent": "nudibranch", + "flow": "cuttlefish", + "transition_route_group": "mussel", } path = FlowsClient.transition_route_group_path(**expected) @@ -9582,10 +9656,10 @@ def test_parse_transition_route_group_path(): def test_webhook_path(): - project = "squid" - location = "clam" - agent = "whelk" - webhook = "octopus" + project = "winkle" + location = "nautilus" + agent = "scallop" + webhook = "abalone" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -9598,10 +9672,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "agent": "cuttlefish", - "webhook": "mussel", + "project": "squid", + "location": "clam", + "agent": "whelk", + "webhook": "octopus", } path = FlowsClient.webhook_path(**expected) @@ -9611,7 +9685,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "winkle" + billing_account = "oyster" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -9621,7 +9695,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nautilus", + "billing_account": "nudibranch", } path = FlowsClient.common_billing_account_path(**expected) @@ -9631,7 +9705,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "scallop" + folder = "cuttlefish" expected = "folders/{folder}".format( folder=folder, ) @@ -9641,7 +9715,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "abalone", + "folder": "mussel", } path = FlowsClient.common_folder_path(**expected) @@ -9651,7 +9725,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "squid" + organization = "winkle" expected = "organizations/{organization}".format( organization=organization, ) @@ -9661,7 +9735,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "clam", + "organization": "nautilus", } path = FlowsClient.common_organization_path(**expected) @@ -9671,7 +9745,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "whelk" + project = "scallop" expected = "projects/{project}".format( project=project, ) @@ -9681,7 +9755,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "octopus", + "project": "abalone", } path = FlowsClient.common_project_path(**expected) @@ -9691,8 +9765,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "oyster" - location = "nudibranch" + project = "squid" + location = "clam" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -9703,8 +9777,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "cuttlefish", - "location": "mussel", + "project": "whelk", + "location": "octopus", } path = FlowsClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py index 9fe6de175f02..5fc202b2bd68 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py @@ -4590,6 +4590,11 @@ def test_create_generator_rest_call_success(request_type): "llm_model_settings": { "model": "model_value", "prompt_text": "prompt_text_value", + "parameters": { + "temperature": 0.1198, + "input_token_limit": 1, + "output_token_limit": 1, + }, }, "model_parameter": { "temperature": 0.1198, @@ -4810,6 +4815,11 @@ def test_update_generator_rest_call_success(request_type): "llm_model_settings": { "model": "model_value", "prompt_text": "prompt_text_value", + "parameters": { + "temperature": 0.1198, + "input_token_limit": 1, + "output_token_limit": 1, + }, }, "model_parameter": { "temperature": 0.1198, diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py index f596a9a3e64a..2946a243b1cf 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py @@ -4656,6 +4656,13 @@ def test_create_page_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "form": { "parameters": [ @@ -5007,6 +5014,13 @@ def test_update_page_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "form": { "parameters": [ @@ -6245,11 +6259,40 @@ def test_parse_flow_path(): assert expected == actual -def test_intent_path(): +def test_generator_path(): project = "oyster" location = "nudibranch" agent = "cuttlefish" - intent = "mussel" + generator = "mussel" + expected = "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + actual = PagesClient.generator_path(project, location, agent, generator) + assert expected == actual + + +def test_parse_generator_path(): + expected = { + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "generator": "abalone", + } + path = PagesClient.generator_path(**expected) + + # Check that the path construction is reversible. + actual = PagesClient.parse_generator_path(path) + assert expected == actual + + +def test_intent_path(): + project = "squid" + location = "clam" + agent = "whelk" + intent = "octopus" expected = "projects/{project}/locations/{location}/agents/{agent}/intents/{intent}".format( project=project, location=location, @@ -6262,10 +6305,10 @@ def test_intent_path(): def test_parse_intent_path(): expected = { - "project": "winkle", - "location": "nautilus", - "agent": "scallop", - "intent": "abalone", + "project": "oyster", + "location": "nudibranch", + "agent": "cuttlefish", + "intent": "mussel", } path = PagesClient.intent_path(**expected) @@ -6275,11 +6318,11 @@ def test_parse_intent_path(): def test_page_path(): - project = "squid" - location = "clam" - agent = "whelk" - flow = "octopus" - page = "oyster" + project = "winkle" + location = "nautilus" + agent = "scallop" + flow = "abalone" + page = "squid" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/pages/{page}".format( project=project, location=location, @@ -6293,11 +6336,11 @@ def test_page_path(): def test_parse_page_path(): expected = { - "project": "nudibranch", - "location": "cuttlefish", - "agent": "mussel", - "flow": "winkle", - "page": "nautilus", + "project": "clam", + "location": "whelk", + "agent": "octopus", + "flow": "oyster", + "page": "nudibranch", } path = PagesClient.page_path(**expected) @@ -6307,10 +6350,10 @@ def test_parse_page_path(): def test_playbook_path(): - project = "scallop" - location = "abalone" - agent = "squid" - playbook = "clam" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + playbook = "nautilus" expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}".format( project=project, location=location, @@ -6323,10 +6366,10 @@ def test_playbook_path(): def test_parse_playbook_path(): expected = { - "project": "whelk", - "location": "octopus", - "agent": "oyster", - "playbook": "nudibranch", + "project": "scallop", + "location": "abalone", + "agent": "squid", + "playbook": "clam", } path = PagesClient.playbook_path(**expected) @@ -6336,10 +6379,10 @@ def test_parse_playbook_path(): def test_tool_path(): - project = "cuttlefish" - location = "mussel" - agent = "winkle" - tool = "nautilus" + project = "whelk" + location = "octopus" + agent = "oyster" + tool = "nudibranch" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -6354,10 +6397,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "scallop", - "location": "abalone", - "agent": "squid", - "tool": "clam", + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "tool": "nautilus", } path = PagesClient.tool_path(**expected) @@ -6367,11 +6410,11 @@ def test_parse_tool_path(): def test_transition_route_group_path(): - project = "whelk" - location = "octopus" - agent = "oyster" - flow = "nudibranch" - transition_route_group = "cuttlefish" + project = "scallop" + location = "abalone" + agent = "squid" + flow = "clam" + transition_route_group = "whelk" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/transitionRouteGroups/{transition_route_group}".format( project=project, location=location, @@ -6387,11 +6430,11 @@ def test_transition_route_group_path(): def test_parse_transition_route_group_path(): expected = { - "project": "mussel", - "location": "winkle", - "agent": "nautilus", - "flow": "scallop", - "transition_route_group": "abalone", + "project": "octopus", + "location": "oyster", + "agent": "nudibranch", + "flow": "cuttlefish", + "transition_route_group": "mussel", } path = PagesClient.transition_route_group_path(**expected) @@ -6401,10 +6444,10 @@ def test_parse_transition_route_group_path(): def test_webhook_path(): - project = "squid" - location = "clam" - agent = "whelk" - webhook = "octopus" + project = "winkle" + location = "nautilus" + agent = "scallop" + webhook = "abalone" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -6417,10 +6460,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "agent": "cuttlefish", - "webhook": "mussel", + "project": "squid", + "location": "clam", + "agent": "whelk", + "webhook": "octopus", } path = PagesClient.webhook_path(**expected) @@ -6430,7 +6473,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "winkle" + billing_account = "oyster" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -6440,7 +6483,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nautilus", + "billing_account": "nudibranch", } path = PagesClient.common_billing_account_path(**expected) @@ -6450,7 +6493,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "scallop" + folder = "cuttlefish" expected = "folders/{folder}".format( folder=folder, ) @@ -6460,7 +6503,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "abalone", + "folder": "mussel", } path = PagesClient.common_folder_path(**expected) @@ -6470,7 +6513,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "squid" + organization = "winkle" expected = "organizations/{organization}".format( organization=organization, ) @@ -6480,7 +6523,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "clam", + "organization": "nautilus", } path = PagesClient.common_organization_path(**expected) @@ -6490,7 +6533,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "whelk" + project = "scallop" expected = "projects/{project}".format( project=project, ) @@ -6500,7 +6543,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "octopus", + "project": "abalone", } path = PagesClient.common_project_path(**expected) @@ -6510,8 +6553,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "oyster" - location = "nudibranch" + project = "squid" + location = "clam" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -6522,8 +6565,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "cuttlefish", - "location": "mussel", + "project": "whelk", + "location": "octopus", } path = PagesClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py index cc33ef69bbc6..8a668d868f06 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py @@ -43,9 +43,18 @@ except ImportError: # pragma: NO COVER HAS_GOOGLE_AUTH_AIO = False -from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template +from google.api_core import ( + future, + gapic_v1, + grpc_helpers, + grpc_helpers_async, + operation, + operations_v1, + path_template, +) from google.api_core import client_options from google.api_core import exceptions as core_exceptions +from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials @@ -66,15 +75,17 @@ ) from google.cloud.dialogflowcx_v3beta1.types import ( advanced_settings, + data_store_connection, example, fulfillment, gcs, generative_settings, + import_strategy, parameter_definition, ) +from google.cloud.dialogflowcx_v3beta1.types import response_message, tool_call, trace from google.cloud.dialogflowcx_v3beta1.types import playbook from google.cloud.dialogflowcx_v3beta1.types import playbook as gcdc_playbook -from google.cloud.dialogflowcx_v3beta1.types import response_message, tool_call CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -1112,6 +1123,7 @@ def test_create_playbook(request_type, transport: str = "grpc"): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) response = client.create_playbook(request) @@ -1130,6 +1142,7 @@ def test_create_playbook(request_type, transport: str = "grpc"): assert response.referenced_playbooks == ["referenced_playbooks_value"] assert response.referenced_flows == ["referenced_flows_value"] assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == gcdc_playbook.Playbook.PlaybookType.TASK def test_create_playbook_non_empty_request_with_auto_populated_field(): @@ -1262,6 +1275,7 @@ async def test_create_playbook_async( referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) ) response = await client.create_playbook(request) @@ -1281,6 +1295,7 @@ async def test_create_playbook_async( assert response.referenced_playbooks == ["referenced_playbooks_value"] assert response.referenced_flows == ["referenced_flows_value"] assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == gcdc_playbook.Playbook.PlaybookType.TASK @pytest.mark.asyncio @@ -2299,6 +2314,7 @@ def test_get_playbook(request_type, transport: str = "grpc"): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=playbook.Playbook.PlaybookType.TASK, ) response = client.get_playbook(request) @@ -2317,6 +2333,7 @@ def test_get_playbook(request_type, transport: str = "grpc"): assert response.referenced_playbooks == ["referenced_playbooks_value"] assert response.referenced_flows == ["referenced_flows_value"] assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == playbook.Playbook.PlaybookType.TASK def test_get_playbook_non_empty_request_with_auto_populated_field(): @@ -2449,6 +2466,7 @@ async def test_get_playbook_async( referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=playbook.Playbook.PlaybookType.TASK, ) ) response = await client.get_playbook(request) @@ -2468,6 +2486,7 @@ async def test_get_playbook_async( assert response.referenced_playbooks == ["referenced_playbooks_value"] assert response.referenced_flows == ["referenced_flows_value"] assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == playbook.Playbook.PlaybookType.TASK @pytest.mark.asyncio @@ -2617,11 +2636,11 @@ async def test_get_playbook_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - gcdc_playbook.UpdatePlaybookRequest, + playbook.ExportPlaybookRequest, dict, ], ) -def test_update_playbook(request_type, transport: str = "grpc"): +def test_export_playbook(request_type, transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2632,37 +2651,22 @@ def test_update_playbook(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gcdc_playbook.Playbook( - name="name_value", - display_name="display_name_value", - goal="goal_value", - token_count=1193, - referenced_playbooks=["referenced_playbooks_value"], - referenced_flows=["referenced_flows_value"], - referenced_tools=["referenced_tools_value"], - ) - response = client.update_playbook(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.export_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = gcdc_playbook.UpdatePlaybookRequest() + request = playbook.ExportPlaybookRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, gcdc_playbook.Playbook) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.goal == "goal_value" - assert response.token_count == 1193 - assert response.referenced_playbooks == ["referenced_playbooks_value"] - assert response.referenced_flows == ["referenced_flows_value"] - assert response.referenced_tools == ["referenced_tools_value"] + assert isinstance(response, future.Future) -def test_update_playbook_non_empty_request_with_auto_populated_field(): +def test_export_playbook_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = PlaybooksClient( @@ -2673,20 +2677,26 @@ def test_update_playbook_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = gcdc_playbook.UpdatePlaybookRequest() + request = playbook.ExportPlaybookRequest( + name="name_value", + playbook_uri="playbook_uri_value", + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.update_playbook(request=request) + client.export_playbook(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gcdc_playbook.UpdatePlaybookRequest() + assert args[0] == playbook.ExportPlaybookRequest( + name="name_value", + playbook_uri="playbook_uri_value", + ) -def test_update_playbook_use_cached_wrapped_rpc(): +def test_export_playbook_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -2700,21 +2710,26 @@ def test_update_playbook_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_playbook in client._transport._wrapped_methods + assert client._transport.export_playbook in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_playbook] = mock_rpc + client._transport._wrapped_methods[client._transport.export_playbook] = mock_rpc request = {} - client.update_playbook(request) + client.export_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.update_playbook(request) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.export_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -2722,7 +2737,7 @@ def test_update_playbook_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_update_playbook_async_use_cached_wrapped_rpc( +async def test_export_playbook_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -2739,7 +2754,7 @@ async def test_update_playbook_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.update_playbook + client._client._transport.export_playbook in client._client._transport._wrapped_methods ) @@ -2747,16 +2762,21 @@ async def test_update_playbook_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.update_playbook + client._client._transport.export_playbook ] = mock_rpc request = {} - await client.update_playbook(request) + await client.export_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.update_playbook(request) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.export_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -2764,8 +2784,8 @@ async def test_update_playbook_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_update_playbook_async( - transport: str = "grpc_asyncio", request_type=gcdc_playbook.UpdatePlaybookRequest +async def test_export_playbook_async( + transport: str = "grpc_asyncio", request_type=playbook.ExportPlaybookRequest ): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), @@ -2777,58 +2797,43 @@ async def test_update_playbook_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcdc_playbook.Playbook( - name="name_value", - display_name="display_name_value", - goal="goal_value", - token_count=1193, - referenced_playbooks=["referenced_playbooks_value"], - referenced_flows=["referenced_flows_value"], - referenced_tools=["referenced_tools_value"], - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.update_playbook(request) + response = await client.export_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = gcdc_playbook.UpdatePlaybookRequest() + request = playbook.ExportPlaybookRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, gcdc_playbook.Playbook) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.goal == "goal_value" - assert response.token_count == 1193 - assert response.referenced_playbooks == ["referenced_playbooks_value"] - assert response.referenced_flows == ["referenced_flows_value"] - assert response.referenced_tools == ["referenced_tools_value"] + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_update_playbook_async_from_dict(): - await test_update_playbook_async(request_type=dict) +async def test_export_playbook_async_from_dict(): + await test_export_playbook_async(request_type=dict) -def test_update_playbook_field_headers(): +def test_export_playbook_field_headers(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = gcdc_playbook.UpdatePlaybookRequest() + request = playbook.ExportPlaybookRequest() - request.playbook.name = "name_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: - call.return_value = gcdc_playbook.Playbook() - client.update_playbook(request) + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.export_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2839,28 +2844,28 @@ def test_update_playbook_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "playbook.name=name_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_playbook_field_headers_async(): +async def test_export_playbook_field_headers_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = gcdc_playbook.UpdatePlaybookRequest() + request = playbook.ExportPlaybookRequest() - request.playbook.name = "name_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcdc_playbook.Playbook() + operations_pb2.Operation(name="operations/op") ) - await client.update_playbook(request) + await client.export_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2871,110 +2876,18 @@ async def test_update_playbook_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "playbook.name=name_value", + "name=name_value", ) in kw["metadata"] -def test_update_playbook_flattened(): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = gcdc_playbook.Playbook() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_playbook( - playbook=gcdc_playbook.Playbook(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].playbook - mock_val = gcdc_playbook.Playbook(name="name_value") - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) - assert arg == mock_val - - -def test_update_playbook_flattened_error(): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_playbook( - gcdc_playbook.UpdatePlaybookRequest(), - playbook=gcdc_playbook.Playbook(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) - - -@pytest.mark.asyncio -async def test_update_playbook_flattened_async(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = gcdc_playbook.Playbook() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcdc_playbook.Playbook() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_playbook( - playbook=gcdc_playbook.Playbook(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].playbook - mock_val = gcdc_playbook.Playbook(name="name_value") - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) - assert arg == mock_val - - -@pytest.mark.asyncio -async def test_update_playbook_flattened_error_async(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.update_playbook( - gcdc_playbook.UpdatePlaybookRequest(), - playbook=gcdc_playbook.Playbook(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) - - @pytest.mark.parametrize( "request_type", [ - playbook.CreatePlaybookVersionRequest, + playbook.ImportPlaybookRequest, dict, ], ) -def test_create_playbook_version(request_type, transport: str = "grpc"): +def test_import_playbook(request_type, transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2985,29 +2898,22 @@ def test_create_playbook_version(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = playbook.PlaybookVersion( - name="name_value", - description="description_value", - ) - response = client.create_playbook_version(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.import_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = playbook.CreatePlaybookVersionRequest() + request = playbook.ImportPlaybookRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, playbook.PlaybookVersion) - assert response.name == "name_value" - assert response.description == "description_value" + assert isinstance(response, future.Future) -def test_create_playbook_version_non_empty_request_with_auto_populated_field(): +def test_import_playbook_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = PlaybooksClient( @@ -3018,26 +2924,26 @@ def test_create_playbook_version_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = playbook.CreatePlaybookVersionRequest( + request = playbook.ImportPlaybookRequest( parent="parent_value", + playbook_uri="playbook_uri_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.create_playbook_version(request=request) + client.import_playbook(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == playbook.CreatePlaybookVersionRequest( + assert args[0] == playbook.ImportPlaybookRequest( parent="parent_value", + playbook_uri="playbook_uri_value", ) -def test_create_playbook_version_use_cached_wrapped_rpc(): +def test_import_playbook_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -3051,26 +2957,26 @@ def test_create_playbook_version_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.create_playbook_version - in client._transport._wrapped_methods - ) + assert client._transport.import_playbook in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_playbook_version - ] = mock_rpc + client._transport._wrapped_methods[client._transport.import_playbook] = mock_rpc request = {} - client.create_playbook_version(request) + client.import_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.create_playbook_version(request) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.import_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -3078,7 +2984,7 @@ def test_create_playbook_version_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_create_playbook_version_async_use_cached_wrapped_rpc( +async def test_import_playbook_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -3095,7 +3001,7 @@ async def test_create_playbook_version_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.create_playbook_version + client._client._transport.import_playbook in client._client._transport._wrapped_methods ) @@ -3103,16 +3009,21 @@ async def test_create_playbook_version_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.create_playbook_version + client._client._transport.import_playbook ] = mock_rpc request = {} - await client.create_playbook_version(request) + await client.import_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.create_playbook_version(request) + # Operation methods call wrapper_fn to build a cached + # client._transport.operations_client instance on first rpc call. + # Subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.import_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -3120,8 +3031,8 @@ async def test_create_playbook_version_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_create_playbook_version_async( - transport: str = "grpc_asyncio", request_type=playbook.CreatePlaybookVersionRequest +async def test_import_playbook_async( + transport: str = "grpc_asyncio", request_type=playbook.ImportPlaybookRequest ): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), @@ -3133,52 +3044,43 @@ async def test_create_playbook_version_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.PlaybookVersion( - name="name_value", - description="description_value", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.create_playbook_version(request) + response = await client.import_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = playbook.CreatePlaybookVersionRequest() + request = playbook.ImportPlaybookRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, playbook.PlaybookVersion) - assert response.name == "name_value" - assert response.description == "description_value" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_create_playbook_version_async_from_dict(): - await test_create_playbook_version_async(request_type=dict) +async def test_import_playbook_async_from_dict(): + await test_import_playbook_async(request_type=dict) -def test_create_playbook_version_field_headers(): +def test_import_playbook_field_headers(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.CreatePlaybookVersionRequest() + request = playbook.ImportPlaybookRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_playbook_version), "__call__" - ) as call: - call.return_value = playbook.PlaybookVersion() - client.create_playbook_version(request) + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.import_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3194,25 +3096,23 @@ def test_create_playbook_version_field_headers(): @pytest.mark.asyncio -async def test_create_playbook_version_field_headers_async(): +async def test_import_playbook_field_headers_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.CreatePlaybookVersionRequest() + request = playbook.ImportPlaybookRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.PlaybookVersion() + operations_pb2.Operation(name="operations/op") ) - await client.create_playbook_version(request) + await client.import_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3227,110 +3127,14 @@ async def test_create_playbook_version_field_headers_async(): ) in kw["metadata"] -def test_create_playbook_version_flattened(): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_playbook_version), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = playbook.PlaybookVersion() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_playbook_version( - parent="parent_value", - playbook_version=playbook.PlaybookVersion(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].playbook_version - mock_val = playbook.PlaybookVersion(name="name_value") - assert arg == mock_val - - -def test_create_playbook_version_flattened_error(): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_playbook_version( - playbook.CreatePlaybookVersionRequest(), - parent="parent_value", - playbook_version=playbook.PlaybookVersion(name="name_value"), - ) - - -@pytest.mark.asyncio -async def test_create_playbook_version_flattened_async(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_playbook_version), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = playbook.PlaybookVersion() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.PlaybookVersion() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_playbook_version( - parent="parent_value", - playbook_version=playbook.PlaybookVersion(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].playbook_version - mock_val = playbook.PlaybookVersion(name="name_value") - assert arg == mock_val - - -@pytest.mark.asyncio -async def test_create_playbook_version_flattened_error_async(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_playbook_version( - playbook.CreatePlaybookVersionRequest(), - parent="parent_value", - playbook_version=playbook.PlaybookVersion(name="name_value"), - ) - - @pytest.mark.parametrize( "request_type", [ - playbook.GetPlaybookVersionRequest, + gcdc_playbook.UpdatePlaybookRequest, dict, ], ) -def test_get_playbook_version(request_type, transport: str = "grpc"): +def test_update_playbook(request_type, transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3341,29 +3145,39 @@ def test_get_playbook_version(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = playbook.PlaybookVersion( + call.return_value = gcdc_playbook.Playbook( name="name_value", - description="description_value", + display_name="display_name_value", + goal="goal_value", + token_count=1193, + referenced_playbooks=["referenced_playbooks_value"], + referenced_flows=["referenced_flows_value"], + referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) - response = client.get_playbook_version(request) + response = client.update_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = playbook.GetPlaybookVersionRequest() + request = gcdc_playbook.UpdatePlaybookRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, playbook.PlaybookVersion) + assert isinstance(response, gcdc_playbook.Playbook) assert response.name == "name_value" - assert response.description == "description_value" + assert response.display_name == "display_name_value" + assert response.goal == "goal_value" + assert response.token_count == 1193 + assert response.referenced_playbooks == ["referenced_playbooks_value"] + assert response.referenced_flows == ["referenced_flows_value"] + assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == gcdc_playbook.Playbook.PlaybookType.TASK -def test_get_playbook_version_non_empty_request_with_auto_populated_field(): +def test_update_playbook_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = PlaybooksClient( @@ -3374,26 +3188,20 @@ def test_get_playbook_version_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = playbook.GetPlaybookVersionRequest( - name="name_value", - ) + request = gcdc_playbook.UpdatePlaybookRequest() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.get_playbook_version(request=request) + client.update_playbook(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == playbook.GetPlaybookVersionRequest( - name="name_value", - ) + assert args[0] == gcdc_playbook.UpdatePlaybookRequest() -def test_get_playbook_version_use_cached_wrapped_rpc(): +def test_update_playbook_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -3407,25 +3215,21 @@ def test_get_playbook_version_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert ( - client._transport.get_playbook_version in client._transport._wrapped_methods - ) + assert client._transport.update_playbook in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.get_playbook_version - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_playbook] = mock_rpc request = {} - client.get_playbook_version(request) + client.update_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_playbook_version(request) + client.update_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -3433,7 +3237,7 @@ def test_get_playbook_version_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_get_playbook_version_async_use_cached_wrapped_rpc( +async def test_update_playbook_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -3450,7 +3254,7 @@ async def test_get_playbook_version_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.get_playbook_version + client._client._transport.update_playbook in client._client._transport._wrapped_methods ) @@ -3458,16 +3262,16 @@ async def test_get_playbook_version_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.get_playbook_version + client._client._transport.update_playbook ] = mock_rpc request = {} - await client.get_playbook_version(request) + await client.update_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.get_playbook_version(request) + await client.update_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -3475,8 +3279,8 @@ async def test_get_playbook_version_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_get_playbook_version_async( - transport: str = "grpc_asyncio", request_type=playbook.GetPlaybookVersionRequest +async def test_update_playbook_async( + transport: str = "grpc_asyncio", request_type=gcdc_playbook.UpdatePlaybookRequest ): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), @@ -3488,52 +3292,60 @@ async def test_get_playbook_version_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.PlaybookVersion( + gcdc_playbook.Playbook( name="name_value", - description="description_value", + display_name="display_name_value", + goal="goal_value", + token_count=1193, + referenced_playbooks=["referenced_playbooks_value"], + referenced_flows=["referenced_flows_value"], + referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) ) - response = await client.get_playbook_version(request) + response = await client.update_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = playbook.GetPlaybookVersionRequest() + request = gcdc_playbook.UpdatePlaybookRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, playbook.PlaybookVersion) + assert isinstance(response, gcdc_playbook.Playbook) assert response.name == "name_value" - assert response.description == "description_value" + assert response.display_name == "display_name_value" + assert response.goal == "goal_value" + assert response.token_count == 1193 + assert response.referenced_playbooks == ["referenced_playbooks_value"] + assert response.referenced_flows == ["referenced_flows_value"] + assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == gcdc_playbook.Playbook.PlaybookType.TASK @pytest.mark.asyncio -async def test_get_playbook_version_async_from_dict(): - await test_get_playbook_version_async(request_type=dict) +async def test_update_playbook_async_from_dict(): + await test_update_playbook_async(request_type=dict) -def test_get_playbook_version_field_headers(): +def test_update_playbook_field_headers(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.GetPlaybookVersionRequest() + request = gcdc_playbook.UpdatePlaybookRequest() - request.name = "name_value" + request.playbook.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_playbook_version), "__call__" - ) as call: - call.return_value = playbook.PlaybookVersion() - client.get_playbook_version(request) + with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: + call.return_value = gcdc_playbook.Playbook() + client.update_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3544,30 +3356,28 @@ def test_get_playbook_version_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "playbook.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_playbook_version_field_headers_async(): +async def test_update_playbook_field_headers_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.GetPlaybookVersionRequest() + request = gcdc_playbook.UpdatePlaybookRequest() - request.name = "name_value" + request.playbook.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.PlaybookVersion() + gcdc_playbook.Playbook() ) - await client.get_playbook_version(request) + await client.update_playbook(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3578,37 +3388,39 @@ async def test_get_playbook_version_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "playbook.name=name_value", ) in kw["metadata"] -def test_get_playbook_version_flattened(): +def test_update_playbook_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = playbook.PlaybookVersion() + call.return_value = gcdc_playbook.Playbook() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_playbook_version( - name="name_value", + client.update_playbook( + playbook=gcdc_playbook.Playbook(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = "name_value" + arg = args[0].playbook + mock_val = gcdc_playbook.Playbook(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val -def test_get_playbook_version_flattened_error(): +def test_update_playbook_flattened_error(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3616,45 +3428,48 @@ def test_get_playbook_version_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_playbook_version( - playbook.GetPlaybookVersionRequest(), - name="name_value", + client.update_playbook( + gcdc_playbook.UpdatePlaybookRequest(), + playbook=gcdc_playbook.Playbook(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_get_playbook_version_flattened_async(): +async def test_update_playbook_flattened_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_playbook_version), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_playbook), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = playbook.PlaybookVersion() + call.return_value = gcdc_playbook.Playbook() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.PlaybookVersion() + gcdc_playbook.Playbook() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_playbook_version( - name="name_value", + response = await client.update_playbook( + playbook=gcdc_playbook.Playbook(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = "name_value" + arg = args[0].playbook + mock_val = gcdc_playbook.Playbook(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val @pytest.mark.asyncio -async def test_get_playbook_version_flattened_error_async(): +async def test_update_playbook_flattened_error_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) @@ -3662,20 +3477,21 @@ async def test_get_playbook_version_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_playbook_version( - playbook.GetPlaybookVersionRequest(), - name="name_value", + await client.update_playbook( + gcdc_playbook.UpdatePlaybookRequest(), + playbook=gcdc_playbook.Playbook(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.parametrize( "request_type", [ - playbook.ListPlaybookVersionsRequest, + playbook.CreatePlaybookVersionRequest, dict, ], ) -def test_list_playbook_versions(request_type, transport: str = "grpc"): +def test_create_playbook_version(request_type, transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3687,26 +3503,28 @@ def test_list_playbook_versions(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.create_playbook_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = playbook.ListPlaybookVersionsResponse( - next_page_token="next_page_token_value", + call.return_value = playbook.PlaybookVersion( + name="name_value", + description="description_value", ) - response = client.list_playbook_versions(request) + response = client.create_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - request = playbook.ListPlaybookVersionsRequest() + request = playbook.CreatePlaybookVersionRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListPlaybookVersionsPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, playbook.PlaybookVersion) + assert response.name == "name_value" + assert response.description == "description_value" -def test_list_playbook_versions_non_empty_request_with_auto_populated_field(): +def test_create_playbook_version_non_empty_request_with_auto_populated_field(): # This test is a coverage failsafe to make sure that UUID4 fields are # automatically populated, according to AIP-4235, with non-empty requests. client = PlaybooksClient( @@ -3717,28 +3535,26 @@ def test_list_playbook_versions_non_empty_request_with_auto_populated_field(): # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. - request = playbook.ListPlaybookVersionsRequest( + request = playbook.CreatePlaybookVersionRequest( parent="parent_value", - page_token="page_token_value", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.create_playbook_version), "__call__" ) as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.list_playbook_versions(request=request) + client.create_playbook_version(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == playbook.ListPlaybookVersionsRequest( + assert args[0] == playbook.CreatePlaybookVersionRequest( parent="parent_value", - page_token="page_token_value", ) -def test_list_playbook_versions_use_cached_wrapped_rpc(): +def test_create_playbook_version_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -3753,7 +3569,7 @@ def test_list_playbook_versions_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.list_playbook_versions + client._transport.create_playbook_version in client._transport._wrapped_methods ) @@ -3763,15 +3579,15 @@ def test_list_playbook_versions_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.list_playbook_versions + client._transport.create_playbook_version ] = mock_rpc request = {} - client.list_playbook_versions(request) + client.create_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_playbook_versions(request) + client.create_playbook_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -3779,7 +3595,7 @@ def test_list_playbook_versions_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_list_playbook_versions_async_use_cached_wrapped_rpc( +async def test_create_playbook_version_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -3796,7 +3612,7 @@ async def test_list_playbook_versions_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.list_playbook_versions + client._client._transport.create_playbook_version in client._client._transport._wrapped_methods ) @@ -3804,16 +3620,16 @@ async def test_list_playbook_versions_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.list_playbook_versions + client._client._transport.create_playbook_version ] = mock_rpc request = {} - await client.list_playbook_versions(request) + await client.create_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.list_playbook_versions(request) + await client.create_playbook_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -3821,8 +3637,8 @@ async def test_list_playbook_versions_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_list_playbook_versions_async( - transport: str = "grpc_asyncio", request_type=playbook.ListPlaybookVersionsRequest +async def test_create_playbook_version_async( + transport: str = "grpc_asyncio", request_type=playbook.CreatePlaybookVersionRequest ): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), @@ -3835,49 +3651,51 @@ async def test_list_playbook_versions_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.create_playbook_version), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.ListPlaybookVersionsResponse( - next_page_token="next_page_token_value", + playbook.PlaybookVersion( + name="name_value", + description="description_value", ) ) - response = await client.list_playbook_versions(request) + response = await client.create_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = playbook.ListPlaybookVersionsRequest() + request = playbook.CreatePlaybookVersionRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListPlaybookVersionsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, playbook.PlaybookVersion) + assert response.name == "name_value" + assert response.description == "description_value" @pytest.mark.asyncio -async def test_list_playbook_versions_async_from_dict(): - await test_list_playbook_versions_async(request_type=dict) +async def test_create_playbook_version_async_from_dict(): + await test_create_playbook_version_async(request_type=dict) -def test_list_playbook_versions_field_headers(): +def test_create_playbook_version_field_headers(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.ListPlaybookVersionsRequest() + request = playbook.CreatePlaybookVersionRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.create_playbook_version), "__call__" ) as call: - call.return_value = playbook.ListPlaybookVersionsResponse() - client.list_playbook_versions(request) + call.return_value = playbook.PlaybookVersion() + client.create_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3893,25 +3711,25 @@ def test_list_playbook_versions_field_headers(): @pytest.mark.asyncio -async def test_list_playbook_versions_field_headers_async(): +async def test_create_playbook_version_field_headers_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.ListPlaybookVersionsRequest() + request = playbook.CreatePlaybookVersionRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.create_playbook_version), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.ListPlaybookVersionsResponse() + playbook.PlaybookVersion() ) - await client.list_playbook_versions(request) + await client.create_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3926,21 +3744,22 @@ async def test_list_playbook_versions_field_headers_async(): ) in kw["metadata"] -def test_list_playbook_versions_flattened(): +def test_create_playbook_version_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.create_playbook_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = playbook.ListPlaybookVersionsResponse() + call.return_value = playbook.PlaybookVersion() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_playbook_versions( + client.create_playbook_version( parent="parent_value", + playbook_version=playbook.PlaybookVersion(name="name_value"), ) # Establish that the underlying call was made with the expected @@ -3950,9 +3769,12 @@ def test_list_playbook_versions_flattened(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val + arg = args[0].playbook_version + mock_val = playbook.PlaybookVersion(name="name_value") + assert arg == mock_val -def test_list_playbook_versions_flattened_error(): +def test_create_playbook_version_flattened_error(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3960,32 +3782,34 @@ def test_list_playbook_versions_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_playbook_versions( - playbook.ListPlaybookVersionsRequest(), + client.create_playbook_version( + playbook.CreatePlaybookVersionRequest(), parent="parent_value", + playbook_version=playbook.PlaybookVersion(name="name_value"), ) @pytest.mark.asyncio -async def test_list_playbook_versions_flattened_async(): +async def test_create_playbook_version_flattened_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.create_playbook_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = playbook.ListPlaybookVersionsResponse() + call.return_value = playbook.PlaybookVersion() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - playbook.ListPlaybookVersionsResponse() + playbook.PlaybookVersion() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_playbook_versions( + response = await client.create_playbook_version( parent="parent_value", + playbook_version=playbook.PlaybookVersion(name="name_value"), ) # Establish that the underlying call was made with the expected @@ -3995,10 +3819,13 @@ async def test_list_playbook_versions_flattened_async(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val + arg = args[0].playbook_version + mock_val = playbook.PlaybookVersion(name="name_value") + assert arg == mock_val @pytest.mark.asyncio -async def test_list_playbook_versions_flattened_error_async(): +async def test_create_playbook_version_flattened_error_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) @@ -4006,280 +3833,84 @@ async def test_list_playbook_versions_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_playbook_versions( - playbook.ListPlaybookVersionsRequest(), + await client.create_playbook_version( + playbook.CreatePlaybookVersionRequest(), parent="parent_value", + playbook_version=playbook.PlaybookVersion(name="name_value"), ) -def test_list_playbook_versions_pager(transport_name: str = "grpc"): +@pytest.mark.parametrize( + "request_type", + [ + playbook.GetPlaybookVersionRequest, + dict, + ], +) +def test_get_playbook_version(request_type, transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + 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 = request_type() + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" + type(client.transport.get_playbook_version), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - next_page_token="abc", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[], - next_page_token="def", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - ], - next_page_token="ghi", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - ), - RuntimeError, - ) - - expected_metadata = () - retry = retries.Retry() - timeout = 5 - expected_metadata = tuple(expected_metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = playbook.PlaybookVersion( + name="name_value", + description="description_value", ) - pager = client.list_playbook_versions(request={}, retry=retry, timeout=timeout) + response = client.get_playbook_version(request) - assert pager._metadata == expected_metadata - assert pager._retry == retry - assert pager._timeout == timeout + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = playbook.GetPlaybookVersionRequest() + assert args[0] == request - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, playbook.PlaybookVersion) for i in results) + # Establish that the response is the type that we expect. + assert isinstance(response, playbook.PlaybookVersion) + assert response.name == "name_value" + assert response.description == "description_value" -def test_list_playbook_versions_pages(transport_name: str = "grpc"): +def test_get_playbook_version_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = playbook.GetPlaybookVersionRequest( + name="name_value", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_playbook_versions), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - next_page_token="abc", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[], - next_page_token="def", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - ], - next_page_token="ghi", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - ), - RuntimeError, - ) - pages = list(client.list_playbook_versions(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_playbook_versions_async_pager(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_playbook_versions), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - next_page_token="abc", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[], - next_page_token="def", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - ], - next_page_token="ghi", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_playbook_versions( - request={}, - ) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, playbook.PlaybookVersion) for i in responses) - - -@pytest.mark.asyncio -async def test_list_playbook_versions_async_pages(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_playbook_versions), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - next_page_token="abc", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[], - next_page_token="def", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - ], - next_page_token="ghi", - ), - playbook.ListPlaybookVersionsResponse( - playbook_versions=[ - playbook.PlaybookVersion(), - playbook.PlaybookVersion(), - ], - ), - RuntimeError, - ) - pages = [] - # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` - # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 - async for page_ in ( # pragma: no branch - await client.list_playbook_versions(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize( - "request_type", - [ - playbook.DeletePlaybookVersionRequest, - dict, - ], -) -def test_delete_playbook_version(request_type, transport: str = "grpc"): - client = PlaybooksClient( - credentials=ga_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 = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_playbook_version), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_playbook_version(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = playbook.DeletePlaybookVersionRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_playbook_version_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = playbook.DeletePlaybookVersionRequest( - name="name_value", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_playbook_version), "__call__" + type(client.transport.get_playbook_version), "__call__" ) as call: call.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client.delete_playbook_version(request=request) + client.get_playbook_version(request=request) call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == playbook.DeletePlaybookVersionRequest( + assert args[0] == playbook.GetPlaybookVersionRequest( name="name_value", ) -def test_delete_playbook_version_use_cached_wrapped_rpc(): +def test_get_playbook_version_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -4294,8 +3925,7 @@ def test_delete_playbook_version_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.delete_playbook_version - in client._transport._wrapped_methods + client._transport.get_playbook_version in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -4304,15 +3934,15 @@ def test_delete_playbook_version_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.delete_playbook_version + client._transport.get_playbook_version ] = mock_rpc request = {} - client.delete_playbook_version(request) + client.get_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.delete_playbook_version(request) + client.get_playbook_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -4320,7 +3950,7 @@ def test_delete_playbook_version_use_cached_wrapped_rpc(): @pytest.mark.asyncio -async def test_delete_playbook_version_async_use_cached_wrapped_rpc( +async def test_get_playbook_version_async_use_cached_wrapped_rpc( transport: str = "grpc_asyncio", ): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, @@ -4337,7 +3967,7 @@ async def test_delete_playbook_version_async_use_cached_wrapped_rpc( # Ensure method has been cached assert ( - client._client._transport.delete_playbook_version + client._client._transport.get_playbook_version in client._client._transport._wrapped_methods ) @@ -4345,16 +3975,16 @@ async def test_delete_playbook_version_async_use_cached_wrapped_rpc( mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() client._client._transport._wrapped_methods[ - client._client._transport.delete_playbook_version + client._client._transport.get_playbook_version ] = mock_rpc request = {} - await client.delete_playbook_version(request) + await client.get_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - await client.delete_playbook_version(request) + await client.get_playbook_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 @@ -4362,8 +3992,8 @@ async def test_delete_playbook_version_async_use_cached_wrapped_rpc( @pytest.mark.asyncio -async def test_delete_playbook_version_async( - transport: str = "grpc_asyncio", request_type=playbook.DeletePlaybookVersionRequest +async def test_get_playbook_version_async( + transport: str = "grpc_asyncio", request_type=playbook.GetPlaybookVersionRequest ): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), @@ -4376,44 +4006,51 @@ async def test_delete_playbook_version_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_playbook_version), "__call__" + type(client.transport.get_playbook_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_playbook_version(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.PlaybookVersion( + name="name_value", + description="description_value", + ) + ) + response = await client.get_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - request = playbook.DeletePlaybookVersionRequest() + request = playbook.GetPlaybookVersionRequest() assert args[0] == request # Establish that the response is the type that we expect. - assert response is None + assert isinstance(response, playbook.PlaybookVersion) + assert response.name == "name_value" + assert response.description == "description_value" @pytest.mark.asyncio -async def test_delete_playbook_version_async_from_dict(): - await test_delete_playbook_version_async(request_type=dict) +async def test_get_playbook_version_async_from_dict(): + await test_get_playbook_version_async(request_type=dict) -def test_delete_playbook_version_field_headers(): +def test_get_playbook_version_field_headers(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.DeletePlaybookVersionRequest() + request = playbook.GetPlaybookVersionRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_playbook_version), "__call__" + type(client.transport.get_playbook_version), "__call__" ) as call: - call.return_value = None - client.delete_playbook_version(request) + call.return_value = playbook.PlaybookVersion() + client.get_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4429,24 +4066,26 @@ def test_delete_playbook_version_field_headers(): @pytest.mark.asyncio -async def test_delete_playbook_version_field_headers_async(): +async def test_get_playbook_version_field_headers_async(): client = PlaybooksAsyncClient( credentials=async_anonymous_credentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = playbook.DeletePlaybookVersionRequest() + request = playbook.GetPlaybookVersionRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_playbook_version), "__call__" + type(client.transport.get_playbook_version), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_playbook_version(request) - + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.PlaybookVersion() + ) + await client.get_playbook_version(request) + # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] @@ -4460,20 +4099,20 @@ async def test_delete_playbook_version_field_headers_async(): ) in kw["metadata"] -def test_delete_playbook_version_flattened(): +def test_get_playbook_version_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_playbook_version), "__call__" + type(client.transport.get_playbook_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = None + call.return_value = playbook.PlaybookVersion() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_playbook_version( + client.get_playbook_version( name="name_value", ) @@ -4486,65 +4125,1897 @@ def test_delete_playbook_version_flattened(): assert arg == mock_val -def test_delete_playbook_version_flattened_error(): +def test_get_playbook_version_flattened_error(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_playbook_version( + playbook.GetPlaybookVersionRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_playbook_version_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = playbook.PlaybookVersion() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.PlaybookVersion() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_playbook_version( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_playbook_version_flattened_error_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_playbook_version( + playbook.GetPlaybookVersionRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + playbook.RestorePlaybookVersionRequest, + dict, + ], +) +def test_restore_playbook_version(request_type, transport: str = "grpc"): + client = PlaybooksClient( + credentials=ga_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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = playbook.RestorePlaybookVersionResponse() + response = client.restore_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = playbook.RestorePlaybookVersionRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, playbook.RestorePlaybookVersionResponse) + + +def test_restore_playbook_version_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = playbook.RestorePlaybookVersionRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.restore_playbook_version(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == playbook.RestorePlaybookVersionRequest( + name="name_value", + ) + + +def test_restore_playbook_version_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.restore_playbook_version + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.restore_playbook_version + ] = mock_rpc + request = {} + client.restore_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.restore_playbook_version(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_restore_playbook_version_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.restore_playbook_version + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.restore_playbook_version + ] = mock_rpc + + request = {} + await client.restore_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.restore_playbook_version(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_restore_playbook_version_async( + transport: str = "grpc_asyncio", request_type=playbook.RestorePlaybookVersionRequest +): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + 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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.RestorePlaybookVersionResponse() + ) + response = await client.restore_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = playbook.RestorePlaybookVersionRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, playbook.RestorePlaybookVersionResponse) + + +@pytest.mark.asyncio +async def test_restore_playbook_version_async_from_dict(): + await test_restore_playbook_version_async(request_type=dict) + + +def test_restore_playbook_version_field_headers(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = playbook.RestorePlaybookVersionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + call.return_value = playbook.RestorePlaybookVersionResponse() + client.restore_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_restore_playbook_version_field_headers_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = playbook.RestorePlaybookVersionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.RestorePlaybookVersionResponse() + ) + await client.restore_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_restore_playbook_version_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = playbook.RestorePlaybookVersionResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.restore_playbook_version( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_restore_playbook_version_flattened_error(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.restore_playbook_version( + playbook.RestorePlaybookVersionRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_restore_playbook_version_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = playbook.RestorePlaybookVersionResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.RestorePlaybookVersionResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.restore_playbook_version( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_restore_playbook_version_flattened_error_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.restore_playbook_version( + playbook.RestorePlaybookVersionRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + playbook.ListPlaybookVersionsRequest, + dict, + ], +) +def test_list_playbook_versions(request_type, transport: str = "grpc"): + client = PlaybooksClient( + credentials=ga_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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = playbook.ListPlaybookVersionsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_playbook_versions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = playbook.ListPlaybookVersionsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListPlaybookVersionsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_playbook_versions_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = playbook.ListPlaybookVersionsRequest( + parent="parent_value", + page_token="page_token_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.list_playbook_versions(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == playbook.ListPlaybookVersionsRequest( + parent="parent_value", + page_token="page_token_value", + ) + + +def test_list_playbook_versions_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_playbook_versions + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_playbook_versions + ] = mock_rpc + request = {} + client.list_playbook_versions(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_playbook_versions(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_list_playbook_versions_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_playbook_versions + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.list_playbook_versions + ] = mock_rpc + + request = {} + await client.list_playbook_versions(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.list_playbook_versions(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_list_playbook_versions_async( + transport: str = "grpc_asyncio", request_type=playbook.ListPlaybookVersionsRequest +): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + 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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.ListPlaybookVersionsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_playbook_versions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = playbook.ListPlaybookVersionsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListPlaybookVersionsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_playbook_versions_async_from_dict(): + await test_list_playbook_versions_async(request_type=dict) + + +def test_list_playbook_versions_field_headers(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = playbook.ListPlaybookVersionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + call.return_value = playbook.ListPlaybookVersionsResponse() + client.list_playbook_versions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_playbook_versions_field_headers_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = playbook.ListPlaybookVersionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.ListPlaybookVersionsResponse() + ) + await client.list_playbook_versions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_playbook_versions_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = playbook.ListPlaybookVersionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_playbook_versions( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_playbook_versions_flattened_error(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_playbook_versions( + playbook.ListPlaybookVersionsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_playbook_versions_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = playbook.ListPlaybookVersionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.ListPlaybookVersionsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_playbook_versions( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_playbook_versions_flattened_error_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_playbook_versions( + playbook.ListPlaybookVersionsRequest(), + parent="parent_value", + ) + + +def test_list_playbook_versions_pager(transport_name: str = "grpc"): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + next_page_token="abc", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[], + next_page_token="def", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + ], + next_page_token="ghi", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + ), + RuntimeError, + ) + + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_playbook_versions(request={}, retry=retry, timeout=timeout) + + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, playbook.PlaybookVersion) for i in results) + + +def test_list_playbook_versions_pages(transport_name: str = "grpc"): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + next_page_token="abc", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[], + next_page_token="def", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + ], + next_page_token="ghi", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + ), + RuntimeError, + ) + pages = list(client.list_playbook_versions(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_playbook_versions_async_pager(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + next_page_token="abc", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[], + next_page_token="def", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + ], + next_page_token="ghi", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_playbook_versions( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, playbook.PlaybookVersion) for i in responses) + + +@pytest.mark.asyncio +async def test_list_playbook_versions_async_pages(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_playbook_versions), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + next_page_token="abc", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[], + next_page_token="def", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + ], + next_page_token="ghi", + ), + playbook.ListPlaybookVersionsResponse( + playbook_versions=[ + playbook.PlaybookVersion(), + playbook.PlaybookVersion(), + ], + ), + RuntimeError, + ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_playbook_versions(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + playbook.DeletePlaybookVersionRequest, + dict, + ], +) +def test_delete_playbook_version(request_type, transport: str = "grpc"): + client = PlaybooksClient( + credentials=ga_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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = playbook.DeletePlaybookVersionRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_playbook_version_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = playbook.DeletePlaybookVersionRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_playbook_version), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.delete_playbook_version(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == playbook.DeletePlaybookVersionRequest( + name="name_value", + ) + + +def test_delete_playbook_version_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_playbook_version + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_playbook_version + ] = mock_rpc + request = {} + client.delete_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.delete_playbook_version(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_delete_playbook_version_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.delete_playbook_version + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_playbook_version + ] = mock_rpc + + request = {} + await client.delete_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.delete_playbook_version(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_delete_playbook_version_async( + transport: str = "grpc_asyncio", request_type=playbook.DeletePlaybookVersionRequest +): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + 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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = playbook.DeletePlaybookVersionRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_playbook_version_async_from_dict(): + await test_delete_playbook_version_async(request_type=dict) + + +def test_delete_playbook_version_field_headers(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = playbook.DeletePlaybookVersionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_playbook_version), "__call__" + ) as call: + call.return_value = None + client.delete_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_playbook_version_field_headers_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = playbook.DeletePlaybookVersionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_playbook_version), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_playbook_version(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_playbook_version_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_playbook_version( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_playbook_version_flattened_error(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_playbook_version( + playbook.DeletePlaybookVersionRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_playbook_version_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_playbook_version( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_playbook_version_flattened_error_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_playbook_version( + playbook.DeletePlaybookVersionRequest(), + name="name_value", + ) + + +def test_create_playbook_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.create_playbook in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.create_playbook] = mock_rpc + + request = {} + client.create_playbook(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.create_playbook(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_create_playbook_rest_required_fields( + request_type=gcdc_playbook.CreatePlaybookRequest, +): + transport_class = transports.PlaybooksRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_playbook._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_playbook._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = gcdc_playbook.Playbook() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = gcdc_playbook.Playbook.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.create_playbook(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_playbook_rest_unset_required_fields(): + transport = transports.PlaybooksRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_playbook._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "playbook", + ) + ) + ) + + +def test_create_playbook_rest_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcdc_playbook.Playbook() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2/agents/sample3"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + playbook=gcdc_playbook.Playbook(name="name_value"), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = gcdc_playbook.Playbook.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.create_playbook(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v3beta1/{parent=projects/*/locations/*/agents/*}/playbooks" + % client.transport._host, + args[1], + ) + + +def test_create_playbook_rest_flattened_error(transport: str = "rest"): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_playbook( + gcdc_playbook.CreatePlaybookRequest(), + parent="parent_value", + playbook=gcdc_playbook.Playbook(name="name_value"), + ) + + +def test_delete_playbook_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_playbook in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.delete_playbook] = mock_rpc + + request = {} + client.delete_playbook(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.delete_playbook(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_playbook_rest_required_fields( + request_type=playbook.DeletePlaybookRequest, +): + transport_class = transports.PlaybooksRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_playbook._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_playbook._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_playbook(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_playbook_rest_unset_required_fields(): + transport = transports.PlaybooksRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_playbook._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_delete_playbook_rest_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_playbook(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*}" + % client.transport._host, + args[1], + ) + + +def test_delete_playbook_rest_flattened_error(transport: str = "rest"): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_playbook( + playbook.DeletePlaybookRequest(), + name="name_value", + ) + + +def test_list_playbooks_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_playbooks in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.list_playbooks] = mock_rpc + + request = {} + client.list_playbooks(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_playbooks(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_playbooks_rest_required_fields( + request_type=playbook.ListPlaybooksRequest, +): + transport_class = transports.PlaybooksRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_playbooks._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_playbooks._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = playbook.ListPlaybooksResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = playbook.ListPlaybooksResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_playbooks(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_playbooks_rest_unset_required_fields(): + transport = transports.PlaybooksRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_playbooks._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_playbooks_rest_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = playbook.ListPlaybooksResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2/agents/sample3"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = playbook.ListPlaybooksResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_playbooks(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v3beta1/{parent=projects/*/locations/*/agents/*}/playbooks" + % client.transport._host, + args[1], + ) + + +def test_list_playbooks_rest_flattened_error(transport: str = "rest"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_playbook_version( - playbook.DeletePlaybookVersionRequest(), - name="name_value", + client.list_playbooks( + playbook.ListPlaybooksRequest(), + parent="parent_value", ) -@pytest.mark.asyncio -async def test_delete_playbook_version_flattened_async(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), +def test_list_playbooks_rest_pager(transport: str = "rest"): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_playbook_version), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_playbook_version( - name="name_value", + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + playbook.ListPlaybooksResponse( + playbooks=[ + playbook.Playbook(), + playbook.Playbook(), + playbook.Playbook(), + ], + next_page_token="abc", + ), + playbook.ListPlaybooksResponse( + playbooks=[], + next_page_token="def", + ), + playbook.ListPlaybooksResponse( + playbooks=[ + playbook.Playbook(), + ], + next_page_token="ghi", + ), + playbook.ListPlaybooksResponse( + playbooks=[ + playbook.Playbook(), + playbook.Playbook(), + ], + ), ) + # Two responses for two calls + response = response + response - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = "name_value" - assert arg == mock_val + # Wrap the values into proper Response objs + response = tuple(playbook.ListPlaybooksResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + sample_request = {"parent": "projects/sample1/locations/sample2/agents/sample3"} -@pytest.mark.asyncio -async def test_delete_playbook_version_flattened_error_async(): - client = PlaybooksAsyncClient( - credentials=async_anonymous_credentials(), - ) + pager = client.list_playbooks(request=sample_request) - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_playbook_version( - playbook.DeletePlaybookVersionRequest(), - name="name_value", - ) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, playbook.Playbook) for i in results) + + pages = list(client.list_playbooks(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_create_playbook_rest_use_cached_wrapped_rpc(): +def test_get_playbook_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -4558,35 +6029,33 @@ def test_create_playbook_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.create_playbook in client._transport._wrapped_methods + assert client._transport.get_playbook in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.create_playbook] = mock_rpc + client._transport._wrapped_methods[client._transport.get_playbook] = mock_rpc request = {} - client.create_playbook(request) + client.get_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.create_playbook(request) + client.get_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_playbook_rest_required_fields( - request_type=gcdc_playbook.CreatePlaybookRequest, -): +def test_get_playbook_rest_required_fields(request_type=playbook.GetPlaybookRequest): transport_class = transports.PlaybooksRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -4597,21 +6066,21 @@ def test_create_playbook_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_playbook._get_unset_required_fields(jsonified_request) + ).get_playbook._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_playbook._get_unset_required_fields(jsonified_request) + ).get_playbook._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4620,7 +6089,7 @@ def test_create_playbook_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcdc_playbook.Playbook() + return_value = playbook.Playbook() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -4632,48 +6101,39 @@ def test_create_playbook_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = gcdc_playbook.Playbook.pb(return_value) + return_value = playbook.Playbook.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_playbook(request) + response = client.get_playbook(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_playbook_rest_unset_required_fields(): +def test_get_playbook_rest_unset_required_fields(): transport = transports.PlaybooksRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_playbook._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(()) - & set( - ( - "parent", - "playbook", - ) - ) - ) + unset_fields = transport.get_playbook._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_create_playbook_rest_flattened(): +def test_get_playbook_rest_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -4682,15 +6142,16 @@ def test_create_playbook_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcdc_playbook.Playbook() + return_value = playbook.Playbook() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2/agents/sample3"} + sample_request = { + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - playbook=gcdc_playbook.Playbook(name="name_value"), + name="name_value", ) mock_args.update(sample_request) @@ -4698,26 +6159,26 @@ def test_create_playbook_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = gcdc_playbook.Playbook.pb(return_value) + return_value = playbook.Playbook.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_playbook(**mock_args) + client.get_playbook(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v3beta1/{parent=projects/*/locations/*/agents/*}/playbooks" + "%s/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*}" % client.transport._host, args[1], ) -def test_create_playbook_rest_flattened_error(transport: str = "rest"): +def test_get_playbook_rest_flattened_error(transport: str = "rest"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -4726,14 +6187,13 @@ def test_create_playbook_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_playbook( - gcdc_playbook.CreatePlaybookRequest(), - parent="parent_value", - playbook=gcdc_playbook.Playbook(name="name_value"), + client.get_playbook( + playbook.GetPlaybookRequest(), + name="name_value", ) -def test_delete_playbook_rest_use_cached_wrapped_rpc(): +def test_export_playbook_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -4747,30 +6207,34 @@ def test_delete_playbook_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_playbook in client._transport._wrapped_methods + assert client._transport.export_playbook in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.delete_playbook] = mock_rpc + client._transport._wrapped_methods[client._transport.export_playbook] = mock_rpc request = {} - client.delete_playbook(request) + client.export_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.delete_playbook(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.export_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_delete_playbook_rest_required_fields( - request_type=playbook.DeletePlaybookRequest, +def test_export_playbook_rest_required_fields( + request_type=playbook.ExportPlaybookRequest, ): transport_class = transports.PlaybooksRestTransport @@ -4786,7 +6250,7 @@ def test_delete_playbook_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_playbook._get_unset_required_fields(jsonified_request) + ).export_playbook._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -4795,7 +6259,7 @@ def test_delete_playbook_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_playbook._get_unset_required_fields(jsonified_request) + ).export_playbook._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -4809,7 +6273,7 @@ def test_delete_playbook_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = None + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -4821,94 +6285,37 @@ def test_delete_playbook_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - json_return_value = "" + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_playbook(request) + response = client.export_playbook(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_playbook_rest_unset_required_fields(): +def test_export_playbook_rest_unset_required_fields(): transport = transports.PlaybooksRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_playbook._get_unset_required_fields({}) + unset_fields = transport.export_playbook._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_delete_playbook_rest_flattened(): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = { - "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" - } - - # get truthy value for each flattened field - mock_args = dict( - name="name_value", - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = "" - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - client.delete_playbook(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*}" - % client.transport._host, - args[1], - ) - - -def test_delete_playbook_rest_flattened_error(transport: str = "rest"): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_playbook( - playbook.DeletePlaybookRequest(), - name="name_value", - ) - - -def test_list_playbooks_rest_use_cached_wrapped_rpc(): +def test_import_playbook_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -4922,30 +6329,34 @@ def test_list_playbooks_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.list_playbooks in client._transport._wrapped_methods + assert client._transport.import_playbook in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.list_playbooks] = mock_rpc + client._transport._wrapped_methods[client._transport.import_playbook] = mock_rpc request = {} - client.list_playbooks(request) + client.import_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.list_playbooks(request) + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.import_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_list_playbooks_rest_required_fields( - request_type=playbook.ListPlaybooksRequest, +def test_import_playbook_rest_required_fields( + request_type=playbook.ImportPlaybookRequest, ): transport_class = transports.PlaybooksRestTransport @@ -4961,7 +6372,7 @@ def test_list_playbooks_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_playbooks._get_unset_required_fields(jsonified_request) + ).import_playbook._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -4970,14 +6381,7 @@ def test_list_playbooks_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_playbooks._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + ).import_playbook._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -4991,7 +6395,7 @@ def test_list_playbooks_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = playbook.ListPlaybooksResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -5003,166 +6407,37 @@ def test_list_playbooks_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = playbook.ListPlaybooksResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_playbooks(request) + response = client.import_playbook(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_playbooks_rest_unset_required_fields(): +def test_import_playbook_rest_unset_required_fields(): transport = transports.PlaybooksRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_playbooks._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) - - -def test_list_playbooks_rest_flattened(): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = playbook.ListPlaybooksResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2/agents/sample3"} - - # get truthy value for each flattened field - mock_args = dict( - parent="parent_value", - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = playbook.ListPlaybooksResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - client.list_playbooks(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v3beta1/{parent=projects/*/locations/*/agents/*}/playbooks" - % client.transport._host, - args[1], - ) - - -def test_list_playbooks_rest_flattened_error(transport: str = "rest"): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_playbooks( - playbook.ListPlaybooksRequest(), - parent="parent_value", - ) - - -def test_list_playbooks_rest_pager(transport: str = "rest"): - client = PlaybooksClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - playbook.ListPlaybooksResponse( - playbooks=[ - playbook.Playbook(), - playbook.Playbook(), - playbook.Playbook(), - ], - next_page_token="abc", - ), - playbook.ListPlaybooksResponse( - playbooks=[], - next_page_token="def", - ), - playbook.ListPlaybooksResponse( - playbooks=[ - playbook.Playbook(), - ], - next_page_token="ghi", - ), - playbook.ListPlaybooksResponse( - playbooks=[ - playbook.Playbook(), - playbook.Playbook(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(playbook.ListPlaybooksResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2/agents/sample3"} - - pager = client.list_playbooks(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, playbook.Playbook) for i in results) - - pages = list(client.list_playbooks(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + unset_fields = transport.import_playbook._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent",))) -def test_get_playbook_rest_use_cached_wrapped_rpc(): +def test_update_playbook_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -5176,33 +6451,34 @@ def test_get_playbook_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.get_playbook in client._transport._wrapped_methods + assert client._transport.update_playbook in client._transport._wrapped_methods # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.get_playbook] = mock_rpc + client._transport._wrapped_methods[client._transport.update_playbook] = mock_rpc request = {} - client.get_playbook(request) + client.update_playbook(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_playbook(request) + client.update_playbook(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_playbook_rest_required_fields(request_type=playbook.GetPlaybookRequest): +def test_update_playbook_rest_required_fields( + request_type=gcdc_playbook.UpdatePlaybookRequest, +): transport_class = transports.PlaybooksRestTransport request_init = {} - request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -5213,21 +6489,19 @@ def test_get_playbook_rest_required_fields(request_type=playbook.GetPlaybookRequ unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_playbook._get_unset_required_fields(jsonified_request) + ).update_playbook._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_playbook._get_unset_required_fields(jsonified_request) + ).update_playbook._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5236,7 +6510,7 @@ def test_get_playbook_rest_required_fields(request_type=playbook.GetPlaybookRequ request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = playbook.Playbook() + return_value = gcdc_playbook.Playbook() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -5248,39 +6522,40 @@ def test_get_playbook_rest_required_fields(request_type=playbook.GetPlaybookRequ pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = playbook.Playbook.pb(return_value) + return_value = gcdc_playbook.Playbook.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_playbook(request) + response = client.update_playbook(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_playbook_rest_unset_required_fields(): +def test_update_playbook_rest_unset_required_fields(): transport = transports.PlaybooksRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_playbook._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.update_playbook._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("playbook",))) -def test_get_playbook_rest_flattened(): +def test_update_playbook_rest_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -5289,16 +6564,19 @@ def test_get_playbook_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = playbook.Playbook() + return_value = gcdc_playbook.Playbook() # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" + "playbook": { + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" + } } # get truthy value for each flattened field mock_args = dict( - name="name_value", + playbook=gcdc_playbook.Playbook(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -5306,26 +6584,26 @@ def test_get_playbook_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = playbook.Playbook.pb(return_value) + return_value = gcdc_playbook.Playbook.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_playbook(**mock_args) + client.update_playbook(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*}" + "%s/v3beta1/{playbook.name=projects/*/locations/*/agents/*/playbooks/*}" % client.transport._host, args[1], ) -def test_get_playbook_rest_flattened_error(transport: str = "rest"): +def test_update_playbook_rest_flattened_error(transport: str = "rest"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -5334,13 +6612,14 @@ def test_get_playbook_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_playbook( - playbook.GetPlaybookRequest(), - name="name_value", + client.update_playbook( + gcdc_playbook.UpdatePlaybookRequest(), + playbook=gcdc_playbook.Playbook(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_update_playbook_rest_use_cached_wrapped_rpc(): +def test_create_playbook_version_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -5354,34 +6633,40 @@ def test_update_playbook_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_playbook in client._transport._wrapped_methods + assert ( + client._transport.create_playbook_version + in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[client._transport.update_playbook] = mock_rpc + client._transport._wrapped_methods[ + client._transport.create_playbook_version + ] = mock_rpc request = {} - client.update_playbook(request) + client.create_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.update_playbook(request) + client.create_playbook_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_update_playbook_rest_required_fields( - request_type=gcdc_playbook.UpdatePlaybookRequest, +def test_create_playbook_version_rest_required_fields( + request_type=playbook.CreatePlaybookVersionRequest, ): transport_class = transports.PlaybooksRestTransport request_init = {} + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -5392,19 +6677,21 @@ def test_update_playbook_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_playbook._get_unset_required_fields(jsonified_request) + ).create_playbook_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present + jsonified_request["parent"] = "parent_value" + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_playbook._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask",)) + ).create_playbook_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5413,7 +6700,7 @@ def test_update_playbook_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcdc_playbook.Playbook() + return_value = playbook.PlaybookVersion() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -5425,7 +6712,7 @@ def test_update_playbook_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "patch", + "method": "post", "query_params": pb_request, } transcode_result["body"] = pb_request @@ -5435,30 +6722,38 @@ def test_update_playbook_rest_required_fields( response_value.status_code = 200 # Convert return value to protobuf type - return_value = gcdc_playbook.Playbook.pb(return_value) + return_value = playbook.PlaybookVersion.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_playbook(request) + response = client.create_playbook_version(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_playbook_rest_unset_required_fields(): +def test_create_playbook_version_rest_unset_required_fields(): transport = transports.PlaybooksRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_playbook._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("playbook",))) + unset_fields = transport.create_playbook_version._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "playbookVersion", + ) + ) + ) -def test_update_playbook_rest_flattened(): +def test_create_playbook_version_rest_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -5467,19 +6762,17 @@ def test_update_playbook_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcdc_playbook.Playbook() + return_value = playbook.PlaybookVersion() # get arguments that satisfy an http rule for this method sample_request = { - "playbook": { - "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" - } + "parent": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" } # get truthy value for each flattened field mock_args = dict( - playbook=gcdc_playbook.Playbook(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + parent="parent_value", + playbook_version=playbook.PlaybookVersion(name="name_value"), ) mock_args.update(sample_request) @@ -5487,26 +6780,26 @@ def test_update_playbook_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = gcdc_playbook.Playbook.pb(return_value) + return_value = playbook.PlaybookVersion.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_playbook(**mock_args) + client.create_playbook_version(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v3beta1/{playbook.name=projects/*/locations/*/agents/*/playbooks/*}" + "%s/v3beta1/{parent=projects/*/locations/*/agents/*/playbooks/*}/versions" % client.transport._host, args[1], ) -def test_update_playbook_rest_flattened_error(transport: str = "rest"): +def test_create_playbook_version_rest_flattened_error(transport: str = "rest"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -5515,14 +6808,14 @@ def test_update_playbook_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_playbook( - gcdc_playbook.UpdatePlaybookRequest(), - playbook=gcdc_playbook.Playbook(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.create_playbook_version( + playbook.CreatePlaybookVersionRequest(), + parent="parent_value", + playbook_version=playbook.PlaybookVersion(name="name_value"), ) -def test_create_playbook_version_rest_use_cached_wrapped_rpc(): +def test_get_playbook_version_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -5537,8 +6830,7 @@ def test_create_playbook_version_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.create_playbook_version - in client._transport._wrapped_methods + client._transport.get_playbook_version in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -5547,29 +6839,29 @@ def test_create_playbook_version_rest_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.create_playbook_version + client._transport.get_playbook_version ] = mock_rpc request = {} - client.create_playbook_version(request) + client.get_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.create_playbook_version(request) + client.get_playbook_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_create_playbook_version_rest_required_fields( - request_type=playbook.CreatePlaybookVersionRequest, +def test_get_playbook_version_rest_required_fields( + request_type=playbook.GetPlaybookVersionRequest, ): transport_class = transports.PlaybooksRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -5580,21 +6872,21 @@ def test_create_playbook_version_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_playbook_version._get_unset_required_fields(jsonified_request) + ).get_playbook_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_playbook_version._get_unset_required_fields(jsonified_request) + ).get_playbook_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5615,10 +6907,9 @@ def test_create_playbook_version_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -5632,31 +6923,23 @@ def test_create_playbook_version_rest_required_fields( req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.create_playbook_version(request) + response = client.get_playbook_version(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_playbook_version_rest_unset_required_fields(): +def test_get_playbook_version_rest_unset_required_fields(): transport = transports.PlaybooksRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_playbook_version._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(()) - & set( - ( - "parent", - "playbookVersion", - ) - ) - ) + unset_fields = transport.get_playbook_version._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) -def test_create_playbook_version_rest_flattened(): +def test_get_playbook_version_rest_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -5669,13 +6952,12 @@ def test_create_playbook_version_rest_flattened(): # get arguments that satisfy an http rule for this method sample_request = { - "parent": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4/versions/sample5" } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - playbook_version=playbook.PlaybookVersion(name="name_value"), + name="name_value", ) mock_args.update(sample_request) @@ -5689,20 +6971,20 @@ def test_create_playbook_version_rest_flattened(): req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.create_playbook_version(**mock_args) + client.get_playbook_version(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v3beta1/{parent=projects/*/locations/*/agents/*/playbooks/*}/versions" + "%s/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*/versions/*}" % client.transport._host, args[1], ) -def test_create_playbook_version_rest_flattened_error(transport: str = "rest"): +def test_get_playbook_version_rest_flattened_error(transport: str = "rest"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -5711,14 +6993,13 @@ def test_create_playbook_version_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_playbook_version( - playbook.CreatePlaybookVersionRequest(), - parent="parent_value", - playbook_version=playbook.PlaybookVersion(name="name_value"), + client.get_playbook_version( + playbook.GetPlaybookVersionRequest(), + name="name_value", ) -def test_get_playbook_version_rest_use_cached_wrapped_rpc(): +def test_restore_playbook_version_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: @@ -5733,7 +7014,8 @@ def test_get_playbook_version_rest_use_cached_wrapped_rpc(): # Ensure method has been cached assert ( - client._transport.get_playbook_version in client._transport._wrapped_methods + client._transport.restore_playbook_version + in client._transport._wrapped_methods ) # Replace cached wrapped function with mock @@ -5742,24 +7024,24 @@ def test_get_playbook_version_rest_use_cached_wrapped_rpc(): "foo" # operation_request.operation in compute client(s) expect a string. ) client._transport._wrapped_methods[ - client._transport.get_playbook_version + client._transport.restore_playbook_version ] = mock_rpc request = {} - client.get_playbook_version(request) + client.restore_playbook_version(request) # Establish that the underlying gRPC stub method was called. assert mock_rpc.call_count == 1 - client.get_playbook_version(request) + client.restore_playbook_version(request) # Establish that a new wrapper was not created for this call assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 -def test_get_playbook_version_rest_required_fields( - request_type=playbook.GetPlaybookVersionRequest, +def test_restore_playbook_version_rest_required_fields( + request_type=playbook.RestorePlaybookVersionRequest, ): transport_class = transports.PlaybooksRestTransport @@ -5775,7 +7057,7 @@ def test_get_playbook_version_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_playbook_version._get_unset_required_fields(jsonified_request) + ).restore_playbook_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -5784,7 +7066,7 @@ def test_get_playbook_version_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_playbook_version._get_unset_required_fields(jsonified_request) + ).restore_playbook_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -5798,7 +7080,7 @@ def test_get_playbook_version_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = playbook.PlaybookVersion() + return_value = playbook.RestorePlaybookVersionResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -5810,39 +7092,40 @@ def test_get_playbook_version_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = playbook.PlaybookVersion.pb(return_value) + return_value = playbook.RestorePlaybookVersionResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_playbook_version(request) + response = client.restore_playbook_version(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_playbook_version_rest_unset_required_fields(): +def test_restore_playbook_version_rest_unset_required_fields(): transport = transports.PlaybooksRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_playbook_version._get_unset_required_fields({}) + unset_fields = transport.restore_playbook_version._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) -def test_get_playbook_version_rest_flattened(): +def test_restore_playbook_version_rest_flattened(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -5851,7 +7134,7 @@ def test_get_playbook_version_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = playbook.PlaybookVersion() + return_value = playbook.RestorePlaybookVersionResponse() # get arguments that satisfy an http rule for this method sample_request = { @@ -5868,26 +7151,26 @@ def test_get_playbook_version_rest_flattened(): response_value = Response() response_value.status_code = 200 # Convert return value to protobuf type - return_value = playbook.PlaybookVersion.pb(return_value) + return_value = playbook.RestorePlaybookVersionResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_playbook_version(**mock_args) + client.restore_playbook_version(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*/versions/*}" + "%s/v3beta1/{name=projects/*/locations/*/agents/*/playbooks/*/versions/*}:restore" % client.transport._host, args[1], ) -def test_get_playbook_version_rest_flattened_error(transport: str = "rest"): +def test_restore_playbook_version_rest_flattened_error(transport: str = "rest"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -5896,8 +7179,8 @@ def test_get_playbook_version_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_playbook_version( - playbook.GetPlaybookVersionRequest(), + client.restore_playbook_version( + playbook.RestorePlaybookVersionRequest(), name="name_value", ) @@ -6537,6 +7820,48 @@ def test_get_playbook_empty_call_grpc(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_export_playbook_empty_call_grpc(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.export_playbook(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.ExportPlaybookRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_import_playbook_empty_call_grpc(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.import_playbook(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.ImportPlaybookRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. def test_update_playbook_empty_call_grpc(): @@ -6604,6 +7929,29 @@ def test_get_playbook_version_empty_call_grpc(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_restore_playbook_version_empty_call_grpc(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + call.return_value = playbook.RestorePlaybookVersionResponse() + client.restore_playbook_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.RestorePlaybookVersionRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. def test_list_playbook_versions_empty_call_grpc(): @@ -6685,6 +8033,7 @@ async def test_create_playbook_empty_call_grpc_asyncio(): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) ) await client.create_playbook(request=None) @@ -6768,6 +8117,7 @@ async def test_get_playbook_empty_call_grpc_asyncio(): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=playbook.Playbook.PlaybookType.TASK, ) ) await client.get_playbook(request=None) @@ -6780,6 +8130,56 @@ async def test_get_playbook_empty_call_grpc_asyncio(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_export_playbook_empty_call_grpc_asyncio(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.export_playbook(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.ExportPlaybookRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_import_playbook_empty_call_grpc_asyncio(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.import_playbook(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.ImportPlaybookRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @pytest.mark.asyncio @@ -6801,6 +8201,7 @@ async def test_update_playbook_empty_call_grpc_asyncio(): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) ) await client.update_playbook(request=None) @@ -6873,6 +8274,33 @@ async def test_get_playbook_version_empty_call_grpc_asyncio(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_restore_playbook_version_empty_call_grpc_asyncio(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + playbook.RestorePlaybookVersionResponse() + ) + await client.restore_playbook_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.RestorePlaybookVersionRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @pytest.mark.asyncio @@ -6978,7 +8406,18 @@ def test_create_playbook_rest_call_success(request_type): "display_name": "display_name_value", "goal": "goal_value", "input_parameter_definitions": [ - {"name": "name_value", "type_": 1, "description": "description_value"} + { + "name": "name_value", + "type_": 1, + "type_schema": { + "inline_schema": {"type_": 1, "items": {}}, + "schema_reference": { + "tool": "tool_value", + "schema": "schema_value", + }, + }, + "description": "description_value", + } ], "output_parameter_definitions": {}, "instruction": { @@ -6997,6 +8436,11 @@ def test_create_playbook_rest_call_success(request_type): "llm_model_settings": { "model": "model_value", "prompt_text": "prompt_text_value", + "parameters": { + "temperature": 0.1198, + "input_token_limit": 1, + "output_token_limit": 1, + }, }, "speech_settings": { "endpointer_sensitivity": 2402, @@ -7095,6 +8539,13 @@ def test_create_playbook_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, }, "lifecycle_handler": { @@ -7104,6 +8555,7 @@ def test_create_playbook_rest_call_success(request_type): }, } ], + "playbook_type": 1, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -7185,6 +8637,7 @@ def get_message_fields(field): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) # Wrap the value into a proper Response obj @@ -7208,6 +8661,7 @@ def get_message_fields(field): assert response.referenced_playbooks == ["referenced_playbooks_value"] assert response.referenced_flows == ["referenced_flows_value"] assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == gcdc_playbook.Playbook.PlaybookType.TASK @pytest.mark.parametrize("null_interceptor", [True, False]) @@ -7554,6 +9008,7 @@ def test_get_playbook_rest_call_success(request_type): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=playbook.Playbook.PlaybookType.TASK, ) # Wrap the value into a proper Response obj @@ -7577,6 +9032,7 @@ def test_get_playbook_rest_call_success(request_type): assert response.referenced_playbooks == ["referenced_playbooks_value"] assert response.referenced_flows == ["referenced_flows_value"] assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == playbook.Playbook.PlaybookType.TASK @pytest.mark.parametrize("null_interceptor", [True, False]) @@ -7637,6 +9093,244 @@ def test_get_playbook_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() +def test_export_playbook_rest_bad_request(request_type=playbook.ExportPlaybookRequest): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.export_playbook(request) + + +@pytest.mark.parametrize( + "request_type", + [ + playbook.ExportPlaybookRequest, + dict, + ], +) +def test_export_playbook_rest_call_success(request_type): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.export_playbook(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_export_playbook_rest_interceptors(null_interceptor): + transport = transports.PlaybooksRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.PlaybooksRestInterceptor(), + ) + client = PlaybooksClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.PlaybooksRestInterceptor, "post_export_playbook" + ) as post, mock.patch.object( + transports.PlaybooksRestInterceptor, "post_export_playbook_with_metadata" + ) as post_with_metadata, mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_export_playbook" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = playbook.ExportPlaybookRequest.pb(playbook.ExportPlaybookRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = playbook.ExportPlaybookRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.export_playbook( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_import_playbook_rest_bad_request(request_type=playbook.ImportPlaybookRequest): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/agents/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.import_playbook(request) + + +@pytest.mark.parametrize( + "request_type", + [ + playbook.ImportPlaybookRequest, + dict, + ], +) +def test_import_playbook_rest_call_success(request_type): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/agents/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.import_playbook(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_import_playbook_rest_interceptors(null_interceptor): + transport = transports.PlaybooksRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.PlaybooksRestInterceptor(), + ) + client = PlaybooksClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.PlaybooksRestInterceptor, "post_import_playbook" + ) as post, mock.patch.object( + transports.PlaybooksRestInterceptor, "post_import_playbook_with_metadata" + ) as post_with_metadata, mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_import_playbook" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = playbook.ImportPlaybookRequest.pb(playbook.ImportPlaybookRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = playbook.ImportPlaybookRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.import_playbook( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + def test_update_playbook_rest_bad_request( request_type=gcdc_playbook.UpdatePlaybookRequest, ): @@ -7689,7 +9383,18 @@ def test_update_playbook_rest_call_success(request_type): "display_name": "display_name_value", "goal": "goal_value", "input_parameter_definitions": [ - {"name": "name_value", "type_": 1, "description": "description_value"} + { + "name": "name_value", + "type_": 1, + "type_schema": { + "inline_schema": {"type_": 1, "items": {}}, + "schema_reference": { + "tool": "tool_value", + "schema": "schema_value", + }, + }, + "description": "description_value", + } ], "output_parameter_definitions": {}, "instruction": { @@ -7708,6 +9413,11 @@ def test_update_playbook_rest_call_success(request_type): "llm_model_settings": { "model": "model_value", "prompt_text": "prompt_text_value", + "parameters": { + "temperature": 0.1198, + "input_token_limit": 1, + "output_token_limit": 1, + }, }, "speech_settings": { "endpointer_sensitivity": 2402, @@ -7806,6 +9516,13 @@ def test_update_playbook_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, }, "lifecycle_handler": { @@ -7815,6 +9532,7 @@ def test_update_playbook_rest_call_success(request_type): }, } ], + "playbook_type": 1, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -7896,6 +9614,7 @@ def get_message_fields(field): referenced_playbooks=["referenced_playbooks_value"], referenced_flows=["referenced_flows_value"], referenced_tools=["referenced_tools_value"], + playbook_type=gcdc_playbook.Playbook.PlaybookType.TASK, ) # Wrap the value into a proper Response obj @@ -7919,6 +9638,7 @@ def get_message_fields(field): assert response.referenced_playbooks == ["referenced_playbooks_value"] assert response.referenced_flows == ["referenced_flows_value"] assert response.referenced_tools == ["referenced_tools_value"] + assert response.playbook_type == gcdc_playbook.Playbook.PlaybookType.TASK @pytest.mark.parametrize("null_interceptor", [True, False]) @@ -8032,7 +9752,18 @@ def test_create_playbook_version_rest_call_success(request_type): "display_name": "display_name_value", "goal": "goal_value", "input_parameter_definitions": [ - {"name": "name_value", "type_": 1, "description": "description_value"} + { + "name": "name_value", + "type_": 1, + "type_schema": { + "inline_schema": {"type_": 1, "items": {}}, + "schema_reference": { + "tool": "tool_value", + "schema": "schema_value", + }, + }, + "description": "description_value", + } ], "output_parameter_definitions": {}, "instruction": { @@ -8051,6 +9782,11 @@ def test_create_playbook_version_rest_call_success(request_type): "llm_model_settings": { "model": "model_value", "prompt_text": "prompt_text_value", + "parameters": { + "temperature": 0.1198, + "input_token_limit": 1, + "output_token_limit": 1, + }, }, "speech_settings": { "endpointer_sensitivity": 2402, @@ -8149,6 +9885,13 @@ def test_create_playbook_version_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, }, "lifecycle_handler": { @@ -8158,6 +9901,7 @@ def test_create_playbook_version_rest_call_success(request_type): }, } ], + "playbook_type": 1, }, "examples": [ { @@ -8168,18 +9912,109 @@ def test_create_playbook_version_rest_call_success(request_type): }, "playbook_output": { "execution_summary": "execution_summary_value", + "state": 1, "action_parameters": {}, }, "actions": [ { - "user_utterance": {"text": "text_value"}, - "agent_utterance": {"text": "text_value"}, + "user_utterance": { + "text": "text_value", + "audio_tokens": [1286, 1287], + "audio": b"audio_blob", + }, + "event": {"event": "event_value", "text": "text_value"}, + "agent_utterance": { + "text": "text_value", + "require_generation": True, + }, "tool_use": { "tool": "tool_value", "display_name": "display_name_value", "action": "action_value", "input_action_parameters": {}, "output_action_parameters": {}, + "data_store_tool_trace": { + "data_store_connection_signals": { + "rewriter_model_call_signals": { + "rendered_prompt": "rendered_prompt_value", + "model_output": "model_output_value", + "model": "model_value", + }, + "rewritten_query": "rewritten_query_value", + "search_snippets": [ + { + "document_title": "document_title_value", + "document_uri": "document_uri_value", + "text": "text_value", + "metadata": {}, + } + ], + "answer_generation_model_call_signals": { + "rendered_prompt": "rendered_prompt_value", + "model_output": "model_output_value", + "model": "model_value", + }, + "answer": "answer_value", + "answer_parts": [ + { + "text": "text_value", + "supporting_indices": [1946, 1947], + } + ], + "cited_snippets": [ + {"search_snippet": {}, "snippet_index": 1402} + ], + "grounding_signals": {"decision": 1, "score": 1}, + "safety_signals": { + "decision": 1, + "banned_phrase_match": 1, + "matched_banned_phrase": "matched_banned_phrase_value", + }, + } + }, + "webhook_tool_trace": { + "webhook_tag": "webhook_tag_value", + "webhook_uri": "webhook_uri_value", + }, + }, + "llm_call": { + "retrieved_examples": [ + { + "example_id": "example_id_value", + "example_display_name": "example_display_name_value", + "retrieval_strategy": 1, + "matched_retrieval_label": "matched_retrieval_label_value", + } + ], + "token_count": { + "total_input_token_count": 2491, + "conversation_context_token_count": 3463, + "example_token_count": 2036, + "total_output_token_count": 2620, + }, + "model": "model_value", + "temperature": 0.1198, + }, + "intent_match": { + "matched_intents": [ + { + "intent_id": "intent_id_value", + "display_name": "display_name_value", + "score": 0.54, + "generative_fallback": {}, + } + ] + }, + "flow_state_update": { + "event_type": "event_type_value", + "page_state": { + "page": "page_value", + "display_name": "display_name_value", + "status": "status_value", + }, + "updated_parameters": {}, + "destination": "destination_value", + "function_call": {"name": "name_value"}, }, "playbook_invocation": { "playbook": "playbook_value", @@ -8195,6 +10030,39 @@ def test_create_playbook_version_rest_call_success(request_type): "output_action_parameters": {}, "flow_state": 1, }, + "playbook_transition": { + "playbook": "playbook_value", + "display_name": "display_name_value", + "input_action_parameters": {}, + }, + "flow_transition": { + "flow": "flow_value", + "display_name": "display_name_value", + "input_action_parameters": {}, + }, + "tts": {}, + "stt": {}, + "display_name": "display_name_value", + "start_time": {}, + "complete_time": {}, + "sub_execution_steps": [ + { + "name": "name_value", + "tags": ["tags_value1", "tags_value2"], + "metrics": [ + { + "name": "name_value", + "value": {}, + "unit": "unit_value", + } + ], + "start_time": {}, + "complete_time": {}, + } + ], + "status": { + "exception": {"error_message": "error_message_value"} + }, } ], "display_name": "display_name_value", @@ -8495,6 +10363,138 @@ def test_get_playbook_version_rest_interceptors(null_interceptor): post_with_metadata.assert_called_once() +def test_restore_playbook_version_rest_bad_request( + request_type=playbook.RestorePlaybookVersionRequest, +): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4/versions/sample5" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.restore_playbook_version(request) + + +@pytest.mark.parametrize( + "request_type", + [ + playbook.RestorePlaybookVersionRequest, + dict, + ], +) +def test_restore_playbook_version_rest_call_success(request_type): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/agents/sample3/playbooks/sample4/versions/sample5" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = playbook.RestorePlaybookVersionResponse() + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = playbook.RestorePlaybookVersionResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.restore_playbook_version(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, playbook.RestorePlaybookVersionResponse) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_restore_playbook_version_rest_interceptors(null_interceptor): + transport = transports.PlaybooksRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.PlaybooksRestInterceptor(), + ) + client = PlaybooksClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.PlaybooksRestInterceptor, "post_restore_playbook_version" + ) as post, mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_restore_playbook_version_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_restore_playbook_version" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = playbook.RestorePlaybookVersionRequest.pb( + playbook.RestorePlaybookVersionRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = playbook.RestorePlaybookVersionResponse.to_json( + playbook.RestorePlaybookVersionResponse() + ) + req.return_value.content = return_value + + request = playbook.RestorePlaybookVersionRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = playbook.RestorePlaybookVersionResponse() + post_with_metadata.return_value = ( + playbook.RestorePlaybookVersionResponse(), + metadata, + ) + + client.restore_playbook_version( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + def test_list_playbook_versions_rest_bad_request( request_type=playbook.ListPlaybookVersionsRequest, ): @@ -9131,6 +11131,46 @@ def test_get_playbook_empty_call_rest(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_export_playbook_empty_call_rest(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.export_playbook), "__call__") as call: + client.export_playbook(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.ExportPlaybookRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_import_playbook_empty_call_rest(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.import_playbook), "__call__") as call: + client.import_playbook(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.ImportPlaybookRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. def test_update_playbook_empty_call_rest(): @@ -9195,6 +11235,28 @@ def test_get_playbook_version_empty_call_rest(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_restore_playbook_version_empty_call_rest(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.restore_playbook_version), "__call__" + ) as call: + client.restore_playbook_version(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = playbook.RestorePlaybookVersionRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. def test_list_playbook_versions_empty_call_rest(): @@ -9239,6 +11301,23 @@ def test_delete_playbook_version_empty_call_rest(): assert args[0] == request_msg +def test_playbooks_rest_lro_client(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + transport = client.transport + + # Ensure that we have an api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.AbstractOperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = PlaybooksClient( @@ -9276,9 +11355,12 @@ def test_playbooks_base_transport(): "delete_playbook", "list_playbooks", "get_playbook", + "export_playbook", + "import_playbook", "update_playbook", "create_playbook_version", "get_playbook_version", + "restore_playbook_version", "list_playbook_versions", "delete_playbook_version", "get_location", @@ -9294,6 +11376,11 @@ def test_playbooks_base_transport(): with pytest.raises(NotImplementedError): transport.close() + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + # Catch all for all remaining methods and properties remainder = [ "kind", @@ -9565,6 +11652,12 @@ def test_playbooks_client_transport_session_collision(transport_name): session1 = client1.transport.get_playbook._session session2 = client2.transport.get_playbook._session assert session1 != session2 + session1 = client1.transport.export_playbook._session + session2 = client2.transport.export_playbook._session + assert session1 != session2 + session1 = client1.transport.import_playbook._session + session2 = client2.transport.import_playbook._session + assert session1 != session2 session1 = client1.transport.update_playbook._session session2 = client2.transport.update_playbook._session assert session1 != session2 @@ -9574,6 +11667,9 @@ def test_playbooks_client_transport_session_collision(transport_name): session1 = client1.transport.get_playbook_version._session session2 = client2.transport.get_playbook_version._session assert session1 != session2 + session1 = client1.transport.restore_playbook_version._session + session2 = client2.transport.restore_playbook_version._session + assert session1 != session2 session1 = client1.transport.list_playbook_versions._session session2 = client2.transport.list_playbook_versions._session assert session1 != session2 @@ -9700,6 +11796,40 @@ def test_playbooks_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel +def test_playbooks_grpc_lro_client(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_playbooks_grpc_lro_async_client(): + client = PlaybooksAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + def test_example_path(): project = "squid" location = "clam" @@ -9763,41 +11893,70 @@ def test_parse_flow_path(): assert expected == actual -def test_playbook_path(): +def test_generator_path(): project = "cuttlefish" location = "mussel" agent = "winkle" - playbook = "nautilus" - expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}".format( + generator = "nautilus" + expected = "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( project=project, location=location, agent=agent, - playbook=playbook, + generator=generator, ) - actual = PlaybooksClient.playbook_path(project, location, agent, playbook) + actual = PlaybooksClient.generator_path(project, location, agent, generator) assert expected == actual -def test_parse_playbook_path(): +def test_parse_generator_path(): expected = { "project": "scallop", "location": "abalone", "agent": "squid", - "playbook": "clam", + "generator": "clam", } - path = PlaybooksClient.playbook_path(**expected) + path = PlaybooksClient.generator_path(**expected) # Check that the path construction is reversible. - actual = PlaybooksClient.parse_playbook_path(path) + actual = PlaybooksClient.parse_generator_path(path) assert expected == actual -def test_playbook_version_path(): +def test_playbook_path(): project = "whelk" location = "octopus" agent = "oyster" playbook = "nudibranch" - version = "cuttlefish" + expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}".format( + project=project, + location=location, + agent=agent, + playbook=playbook, + ) + actual = PlaybooksClient.playbook_path(project, location, agent, playbook) + assert expected == actual + + +def test_parse_playbook_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "playbook": "nautilus", + } + path = PlaybooksClient.playbook_path(**expected) + + # Check that the path construction is reversible. + actual = PlaybooksClient.parse_playbook_path(path) + assert expected == actual + + +def test_playbook_version_path(): + project = "scallop" + location = "abalone" + agent = "squid" + playbook = "clam" + version = "whelk" expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}/versions/{version}".format( project=project, location=location, @@ -9813,11 +11972,11 @@ def test_playbook_version_path(): def test_parse_playbook_version_path(): expected = { - "project": "mussel", - "location": "winkle", - "agent": "nautilus", - "playbook": "scallop", - "version": "abalone", + "project": "octopus", + "location": "oyster", + "agent": "nudibranch", + "playbook": "cuttlefish", + "version": "mussel", } path = PlaybooksClient.playbook_version_path(**expected) @@ -9827,10 +11986,10 @@ def test_parse_playbook_version_path(): def test_tool_path(): - project = "squid" - location = "clam" - agent = "whelk" - tool = "octopus" + project = "winkle" + location = "nautilus" + agent = "scallop" + tool = "abalone" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -9845,10 +12004,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "agent": "cuttlefish", - "tool": "mussel", + "project": "squid", + "location": "clam", + "agent": "whelk", + "tool": "octopus", } path = PlaybooksClient.tool_path(**expected) @@ -9858,10 +12017,10 @@ def test_parse_tool_path(): def test_webhook_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - webhook = "abalone" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + webhook = "mussel" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -9874,10 +12033,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "webhook": "octopus", + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "webhook": "abalone", } path = PlaybooksClient.webhook_path(**expected) @@ -9887,7 +12046,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "squid" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -9897,7 +12056,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "clam", } path = PlaybooksClient.common_billing_account_path(**expected) @@ -9907,7 +12066,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "whelk" expected = "folders/{folder}".format( folder=folder, ) @@ -9917,7 +12076,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "octopus", } path = PlaybooksClient.common_folder_path(**expected) @@ -9927,7 +12086,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "oyster" expected = "organizations/{organization}".format( organization=organization, ) @@ -9937,7 +12096,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "nudibranch", } path = PlaybooksClient.common_organization_path(**expected) @@ -9947,7 +12106,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "cuttlefish" expected = "projects/{project}".format( project=project, ) @@ -9957,7 +12116,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "mussel", } path = PlaybooksClient.common_project_path(**expected) @@ -9967,8 +12126,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "winkle" + location = "nautilus" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -9979,8 +12138,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "scallop", + "location": "abalone", } path = PlaybooksClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py index e0838813557a..9922ed0e6091 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py @@ -5102,11 +5102,40 @@ def test_parse_flow_path(): assert expected == actual -def test_intent_path(): +def test_generator_path(): project = "winkle" location = "nautilus" agent = "scallop" - intent = "abalone" + generator = "abalone" + expected = "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + actual = SessionsClient.generator_path(project, location, agent, generator) + assert expected == actual + + +def test_parse_generator_path(): + expected = { + "project": "squid", + "location": "clam", + "agent": "whelk", + "generator": "octopus", + } + path = SessionsClient.generator_path(**expected) + + # Check that the path construction is reversible. + actual = SessionsClient.parse_generator_path(path) + assert expected == actual + + +def test_intent_path(): + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + intent = "mussel" expected = "projects/{project}/locations/{location}/agents/{agent}/intents/{intent}".format( project=project, location=location, @@ -5119,10 +5148,10 @@ def test_intent_path(): def test_parse_intent_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "intent": "octopus", + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "intent": "abalone", } path = SessionsClient.intent_path(**expected) @@ -5132,11 +5161,11 @@ def test_parse_intent_path(): def test_page_path(): - project = "oyster" - location = "nudibranch" - agent = "cuttlefish" - flow = "mussel" - page = "winkle" + project = "squid" + location = "clam" + agent = "whelk" + flow = "octopus" + page = "oyster" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/pages/{page}".format( project=project, location=location, @@ -5150,11 +5179,11 @@ def test_page_path(): def test_parse_page_path(): expected = { - "project": "nautilus", - "location": "scallop", - "agent": "abalone", - "flow": "squid", - "page": "clam", + "project": "nudibranch", + "location": "cuttlefish", + "agent": "mussel", + "flow": "winkle", + "page": "nautilus", } path = SessionsClient.page_path(**expected) @@ -5164,10 +5193,10 @@ def test_parse_page_path(): def test_playbook_path(): - project = "whelk" - location = "octopus" - agent = "oyster" - playbook = "nudibranch" + project = "scallop" + location = "abalone" + agent = "squid" + playbook = "clam" expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}".format( project=project, location=location, @@ -5180,10 +5209,10 @@ def test_playbook_path(): def test_parse_playbook_path(): expected = { - "project": "cuttlefish", - "location": "mussel", - "agent": "winkle", - "playbook": "nautilus", + "project": "whelk", + "location": "octopus", + "agent": "oyster", + "playbook": "nudibranch", } path = SessionsClient.playbook_path(**expected) @@ -5193,10 +5222,10 @@ def test_parse_playbook_path(): def test_session_path(): - project = "scallop" - location = "abalone" - agent = "squid" - session = "clam" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + session = "nautilus" expected = "projects/{project}/locations/{location}/agents/{agent}/sessions/{session}".format( project=project, location=location, @@ -5209,10 +5238,10 @@ def test_session_path(): def test_parse_session_path(): expected = { - "project": "whelk", - "location": "octopus", - "agent": "oyster", - "session": "nudibranch", + "project": "scallop", + "location": "abalone", + "agent": "squid", + "session": "clam", } path = SessionsClient.session_path(**expected) @@ -5222,11 +5251,11 @@ def test_parse_session_path(): def test_session_entity_type_path(): - project = "cuttlefish" - location = "mussel" - agent = "winkle" - session = "nautilus" - entity_type = "scallop" + project = "whelk" + location = "octopus" + agent = "oyster" + session = "nudibranch" + entity_type = "cuttlefish" expected = "projects/{project}/locations/{location}/agents/{agent}/sessions/{session}/entityTypes/{entity_type}".format( project=project, location=location, @@ -5242,11 +5271,11 @@ def test_session_entity_type_path(): def test_parse_session_entity_type_path(): expected = { - "project": "abalone", - "location": "squid", - "agent": "clam", - "session": "whelk", - "entity_type": "octopus", + "project": "mussel", + "location": "winkle", + "agent": "nautilus", + "session": "scallop", + "entity_type": "abalone", } path = SessionsClient.session_entity_type_path(**expected) @@ -5256,10 +5285,10 @@ def test_parse_session_entity_type_path(): def test_tool_path(): - project = "oyster" - location = "nudibranch" - agent = "cuttlefish" - tool = "mussel" + project = "squid" + location = "clam" + agent = "whelk" + tool = "octopus" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -5274,10 +5303,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "winkle", - "location": "nautilus", - "agent": "scallop", - "tool": "abalone", + "project": "oyster", + "location": "nudibranch", + "agent": "cuttlefish", + "tool": "mussel", } path = SessionsClient.tool_path(**expected) @@ -5287,11 +5316,11 @@ def test_parse_tool_path(): def test_transition_route_group_path(): - project = "squid" - location = "clam" - agent = "whelk" - flow = "octopus" - transition_route_group = "oyster" + project = "winkle" + location = "nautilus" + agent = "scallop" + flow = "abalone" + transition_route_group = "squid" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/transitionRouteGroups/{transition_route_group}".format( project=project, location=location, @@ -5307,11 +5336,11 @@ def test_transition_route_group_path(): def test_parse_transition_route_group_path(): expected = { - "project": "nudibranch", - "location": "cuttlefish", - "agent": "mussel", - "flow": "winkle", - "transition_route_group": "nautilus", + "project": "clam", + "location": "whelk", + "agent": "octopus", + "flow": "oyster", + "transition_route_group": "nudibranch", } path = SessionsClient.transition_route_group_path(**expected) @@ -5321,11 +5350,11 @@ def test_parse_transition_route_group_path(): def test_version_path(): - project = "scallop" - location = "abalone" - agent = "squid" - flow = "clam" - version = "whelk" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + flow = "nautilus" + version = "scallop" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/versions/{version}".format( project=project, location=location, @@ -5339,11 +5368,11 @@ def test_version_path(): def test_parse_version_path(): expected = { - "project": "octopus", - "location": "oyster", - "agent": "nudibranch", - "flow": "cuttlefish", - "version": "mussel", + "project": "abalone", + "location": "squid", + "agent": "clam", + "flow": "whelk", + "version": "octopus", } path = SessionsClient.version_path(**expected) @@ -5353,10 +5382,10 @@ def test_parse_version_path(): def test_webhook_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - webhook = "abalone" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + webhook = "mussel" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -5369,10 +5398,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "webhook": "octopus", + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "webhook": "abalone", } path = SessionsClient.webhook_path(**expected) @@ -5382,7 +5411,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "squid" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -5392,7 +5421,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "clam", } path = SessionsClient.common_billing_account_path(**expected) @@ -5402,7 +5431,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "whelk" expected = "folders/{folder}".format( folder=folder, ) @@ -5412,7 +5441,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "octopus", } path = SessionsClient.common_folder_path(**expected) @@ -5422,7 +5451,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "oyster" expected = "organizations/{organization}".format( organization=organization, ) @@ -5432,7 +5461,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "nudibranch", } path = SessionsClient.common_organization_path(**expected) @@ -5442,7 +5471,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "cuttlefish" expected = "projects/{project}".format( project=project, ) @@ -5452,7 +5481,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "mussel", } path = SessionsClient.common_project_path(**expected) @@ -5462,8 +5491,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "winkle" + location = "nautilus" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -5474,8 +5503,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "scallop", + "location": "abalone", } path = SessionsClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py index ba7b23bcde10..32cc6dcde0fb 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py @@ -8565,6 +8565,13 @@ def test_create_test_case_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "form": { "parameters": [ @@ -9038,6 +9045,13 @@ def test_update_test_case_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "form": { "parameters": [ @@ -11368,11 +11382,40 @@ def test_parse_flow_path(): assert expected == actual -def test_intent_path(): +def test_generator_path(): project = "cuttlefish" location = "mussel" agent = "winkle" - intent = "nautilus" + generator = "nautilus" + expected = "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + actual = TestCasesClient.generator_path(project, location, agent, generator) + assert expected == actual + + +def test_parse_generator_path(): + expected = { + "project": "scallop", + "location": "abalone", + "agent": "squid", + "generator": "clam", + } + path = TestCasesClient.generator_path(**expected) + + # Check that the path construction is reversible. + actual = TestCasesClient.parse_generator_path(path) + assert expected == actual + + +def test_intent_path(): + project = "whelk" + location = "octopus" + agent = "oyster" + intent = "nudibranch" expected = "projects/{project}/locations/{location}/agents/{agent}/intents/{intent}".format( project=project, location=location, @@ -11385,10 +11428,10 @@ def test_intent_path(): def test_parse_intent_path(): expected = { - "project": "scallop", - "location": "abalone", - "agent": "squid", - "intent": "clam", + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "intent": "nautilus", } path = TestCasesClient.intent_path(**expected) @@ -11398,11 +11441,11 @@ def test_parse_intent_path(): def test_page_path(): - project = "whelk" - location = "octopus" - agent = "oyster" - flow = "nudibranch" - page = "cuttlefish" + project = "scallop" + location = "abalone" + agent = "squid" + flow = "clam" + page = "whelk" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/pages/{page}".format( project=project, location=location, @@ -11416,11 +11459,11 @@ def test_page_path(): def test_parse_page_path(): expected = { - "project": "mussel", - "location": "winkle", - "agent": "nautilus", - "flow": "scallop", - "page": "abalone", + "project": "octopus", + "location": "oyster", + "agent": "nudibranch", + "flow": "cuttlefish", + "page": "mussel", } path = TestCasesClient.page_path(**expected) @@ -11430,10 +11473,10 @@ def test_parse_page_path(): def test_playbook_path(): - project = "squid" - location = "clam" - agent = "whelk" - playbook = "octopus" + project = "winkle" + location = "nautilus" + agent = "scallop" + playbook = "abalone" expected = "projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}".format( project=project, location=location, @@ -11446,10 +11489,10 @@ def test_playbook_path(): def test_parse_playbook_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "agent": "cuttlefish", - "playbook": "mussel", + "project": "squid", + "location": "clam", + "agent": "whelk", + "playbook": "octopus", } path = TestCasesClient.playbook_path(**expected) @@ -11459,10 +11502,10 @@ def test_parse_playbook_path(): def test_test_case_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - test_case = "abalone" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + test_case = "mussel" expected = "projects/{project}/locations/{location}/agents/{agent}/testCases/{test_case}".format( project=project, location=location, @@ -11475,10 +11518,10 @@ def test_test_case_path(): def test_parse_test_case_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "test_case": "octopus", + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "test_case": "abalone", } path = TestCasesClient.test_case_path(**expected) @@ -11488,11 +11531,11 @@ def test_parse_test_case_path(): def test_test_case_result_path(): - project = "oyster" - location = "nudibranch" - agent = "cuttlefish" - test_case = "mussel" - result = "winkle" + project = "squid" + location = "clam" + agent = "whelk" + test_case = "octopus" + result = "oyster" expected = "projects/{project}/locations/{location}/agents/{agent}/testCases/{test_case}/results/{result}".format( project=project, location=location, @@ -11508,11 +11551,11 @@ def test_test_case_result_path(): def test_parse_test_case_result_path(): expected = { - "project": "nautilus", - "location": "scallop", - "agent": "abalone", - "test_case": "squid", - "result": "clam", + "project": "nudibranch", + "location": "cuttlefish", + "agent": "mussel", + "test_case": "winkle", + "result": "nautilus", } path = TestCasesClient.test_case_result_path(**expected) @@ -11522,10 +11565,10 @@ def test_parse_test_case_result_path(): def test_tool_path(): - project = "whelk" - location = "octopus" - agent = "oyster" - tool = "nudibranch" + project = "scallop" + location = "abalone" + agent = "squid" + tool = "clam" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -11540,10 +11583,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "cuttlefish", - "location": "mussel", - "agent": "winkle", - "tool": "nautilus", + "project": "whelk", + "location": "octopus", + "agent": "oyster", + "tool": "nudibranch", } path = TestCasesClient.tool_path(**expected) @@ -11553,11 +11596,11 @@ def test_parse_tool_path(): def test_transition_route_group_path(): - project = "scallop" - location = "abalone" - agent = "squid" - flow = "clam" - transition_route_group = "whelk" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + flow = "nautilus" + transition_route_group = "scallop" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/transitionRouteGroups/{transition_route_group}".format( project=project, location=location, @@ -11573,11 +11616,11 @@ def test_transition_route_group_path(): def test_parse_transition_route_group_path(): expected = { - "project": "octopus", - "location": "oyster", - "agent": "nudibranch", - "flow": "cuttlefish", - "transition_route_group": "mussel", + "project": "abalone", + "location": "squid", + "agent": "clam", + "flow": "whelk", + "transition_route_group": "octopus", } path = TestCasesClient.transition_route_group_path(**expected) @@ -11587,10 +11630,10 @@ def test_parse_transition_route_group_path(): def test_webhook_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - webhook = "abalone" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + webhook = "mussel" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -11603,10 +11646,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "webhook": "octopus", + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "webhook": "abalone", } path = TestCasesClient.webhook_path(**expected) @@ -11616,7 +11659,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "squid" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -11626,7 +11669,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "clam", } path = TestCasesClient.common_billing_account_path(**expected) @@ -11636,7 +11679,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "whelk" expected = "folders/{folder}".format( folder=folder, ) @@ -11646,7 +11689,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "octopus", } path = TestCasesClient.common_folder_path(**expected) @@ -11656,7 +11699,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "oyster" expected = "organizations/{organization}".format( organization=organization, ) @@ -11666,7 +11709,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "nudibranch", } path = TestCasesClient.common_organization_path(**expected) @@ -11676,7 +11719,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "cuttlefish" expected = "projects/{project}".format( project=project, ) @@ -11686,7 +11729,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "mussel", } path = TestCasesClient.common_project_path(**expected) @@ -11696,8 +11739,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "winkle" + location = "nautilus" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -11708,8 +11751,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "scallop", + "location": "abalone", } path = TestCasesClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py index 9a9f7049fe35..f017afee3208 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py @@ -7848,17 +7848,22 @@ def test_create_tool_rest_call_success(request_type): "api_key_config": { "key_name": "key_name_value", "api_key": "api_key_value", + "secret_version_for_api_key": "secret_version_for_api_key_value", "request_location": 1, }, "oauth_config": { "oauth_grant_type": 1, "client_id": "client_id_value", "client_secret": "client_secret_value", + "secret_version_for_client_secret": "secret_version_for_client_secret_value", "token_endpoint": "token_endpoint_value", "scopes": ["scopes_value1", "scopes_value2"], }, "service_agent_auth_config": {"service_agent_auth": 1}, - "bearer_token_config": {"token": "token_value"}, + "bearer_token_config": { + "token": "token_value", + "secret_version_for_token": "secret_version_for_token_value", + }, }, "tls_config": { "ca_certs": [ @@ -8484,17 +8489,22 @@ def test_update_tool_rest_call_success(request_type): "api_key_config": { "key_name": "key_name_value", "api_key": "api_key_value", + "secret_version_for_api_key": "secret_version_for_api_key_value", "request_location": 1, }, "oauth_config": { "oauth_grant_type": 1, "client_id": "client_id_value", "client_secret": "client_secret_value", + "secret_version_for_client_secret": "secret_version_for_client_secret_value", "token_endpoint": "token_endpoint_value", "scopes": ["scopes_value1", "scopes_value2"], }, "service_agent_auth_config": {"service_agent_auth": 1}, - "bearer_token_config": {"token": "token_value"}, + "bearer_token_config": { + "token": "token_value", + "secret_version_for_token": "secret_version_for_token_value", + }, }, "tls_config": { "ca_certs": [ @@ -8986,17 +8996,22 @@ def test_create_tool_version_rest_call_success(request_type): "api_key_config": { "key_name": "key_name_value", "api_key": "api_key_value", + "secret_version_for_api_key": "secret_version_for_api_key_value", "request_location": 1, }, "oauth_config": { "oauth_grant_type": 1, "client_id": "client_id_value", "client_secret": "client_secret_value", + "secret_version_for_client_secret": "secret_version_for_client_secret_value", "token_endpoint": "token_endpoint_value", "scopes": ["scopes_value1", "scopes_value2"], }, "service_agent_auth_config": {"service_agent_auth": 1}, - "bearer_token_config": {"token": "token_value"}, + "bearer_token_config": { + "token": "token_value", + "secret_version_for_token": "secret_version_for_token_value", + }, }, "tls_config": { "ca_certs": [ @@ -10626,11 +10641,37 @@ def test_tools_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_service_path(): +def test_secret_version_path(): project = "squid" - location = "clam" - namespace = "whelk" - service = "octopus" + secret = "clam" + version = "whelk" + expected = "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + actual = ToolsClient.secret_version_path(project, secret, version) + assert expected == actual + + +def test_parse_secret_version_path(): + expected = { + "project": "octopus", + "secret": "oyster", + "version": "nudibranch", + } + path = ToolsClient.secret_version_path(**expected) + + # Check that the path construction is reversible. + actual = ToolsClient.parse_secret_version_path(path) + assert expected == actual + + +def test_service_path(): + project = "cuttlefish" + location = "mussel" + namespace = "winkle" + service = "nautilus" expected = "projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}".format( project=project, location=location, @@ -10643,10 +10684,10 @@ def test_service_path(): def test_parse_service_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "namespace": "cuttlefish", - "service": "mussel", + "project": "scallop", + "location": "abalone", + "namespace": "squid", + "service": "clam", } path = ToolsClient.service_path(**expected) @@ -10656,10 +10697,10 @@ def test_parse_service_path(): def test_tool_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - tool = "abalone" + project = "whelk" + location = "octopus" + agent = "oyster" + tool = "nudibranch" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -10674,10 +10715,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "tool": "octopus", + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "tool": "nautilus", } path = ToolsClient.tool_path(**expected) @@ -10687,11 +10728,11 @@ def test_parse_tool_path(): def test_tool_version_path(): - project = "oyster" - location = "nudibranch" - agent = "cuttlefish" - tool = "mussel" - version = "winkle" + project = "scallop" + location = "abalone" + agent = "squid" + tool = "clam" + version = "whelk" expected = "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}/versions/{version}".format( project=project, location=location, @@ -10705,11 +10746,11 @@ def test_tool_version_path(): def test_parse_tool_version_path(): expected = { - "project": "nautilus", - "location": "scallop", - "agent": "abalone", - "tool": "squid", - "version": "clam", + "project": "octopus", + "location": "oyster", + "agent": "nudibranch", + "tool": "cuttlefish", + "version": "mussel", } path = ToolsClient.tool_version_path(**expected) @@ -10719,7 +10760,7 @@ def test_parse_tool_version_path(): def test_common_billing_account_path(): - billing_account = "whelk" + billing_account = "winkle" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -10729,7 +10770,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "octopus", + "billing_account": "nautilus", } path = ToolsClient.common_billing_account_path(**expected) @@ -10739,7 +10780,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "oyster" + folder = "scallop" expected = "folders/{folder}".format( folder=folder, ) @@ -10749,7 +10790,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "nudibranch", + "folder": "abalone", } path = ToolsClient.common_folder_path(**expected) @@ -10759,7 +10800,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "cuttlefish" + organization = "squid" expected = "organizations/{organization}".format( organization=organization, ) @@ -10769,7 +10810,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "mussel", + "organization": "clam", } path = ToolsClient.common_organization_path(**expected) @@ -10779,7 +10820,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "winkle" + project = "whelk" expected = "projects/{project}".format( project=project, ) @@ -10789,7 +10830,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "nautilus", + "project": "octopus", } path = ToolsClient.common_project_path(**expected) @@ -10799,8 +10840,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "scallop" - location = "abalone" + project = "oyster" + location = "nudibranch" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -10811,8 +10852,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "squid", - "location": "clam", + "project": "cuttlefish", + "location": "mussel", } path = ToolsClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py index 173489378886..153e7b0eff83 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py @@ -5029,6 +5029,13 @@ def test_create_transition_route_group_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "target_page": "target_page_value", "target_flow": "target_flow_value", @@ -5353,6 +5360,13 @@ def test_update_transition_route_group_rest_call_success(request_type): }, }, "enable_generative_fallback": True, + "generators": [ + { + "generator": "generator_value", + "input_parameters": {}, + "output_parameter": "output_parameter_value", + } + ], }, "target_page": "target_page_value", "target_flow": "target_flow_value", @@ -6556,11 +6570,42 @@ def test_parse_flow_path(): assert expected == actual -def test_intent_path(): +def test_generator_path(): project = "winkle" location = "nautilus" agent = "scallop" - intent = "abalone" + generator = "abalone" + expected = "projects/{project}/locations/{location}/agents/{agent}/generators/{generator}".format( + project=project, + location=location, + agent=agent, + generator=generator, + ) + actual = TransitionRouteGroupsClient.generator_path( + project, location, agent, generator + ) + assert expected == actual + + +def test_parse_generator_path(): + expected = { + "project": "squid", + "location": "clam", + "agent": "whelk", + "generator": "octopus", + } + path = TransitionRouteGroupsClient.generator_path(**expected) + + # Check that the path construction is reversible. + actual = TransitionRouteGroupsClient.parse_generator_path(path) + assert expected == actual + + +def test_intent_path(): + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + intent = "mussel" expected = "projects/{project}/locations/{location}/agents/{agent}/intents/{intent}".format( project=project, location=location, @@ -6573,10 +6618,10 @@ def test_intent_path(): def test_parse_intent_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "intent": "octopus", + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "intent": "abalone", } path = TransitionRouteGroupsClient.intent_path(**expected) @@ -6586,11 +6631,11 @@ def test_parse_intent_path(): def test_page_path(): - project = "oyster" - location = "nudibranch" - agent = "cuttlefish" - flow = "mussel" - page = "winkle" + project = "squid" + location = "clam" + agent = "whelk" + flow = "octopus" + page = "oyster" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/pages/{page}".format( project=project, location=location, @@ -6604,11 +6649,11 @@ def test_page_path(): def test_parse_page_path(): expected = { - "project": "nautilus", - "location": "scallop", - "agent": "abalone", - "flow": "squid", - "page": "clam", + "project": "nudibranch", + "location": "cuttlefish", + "agent": "mussel", + "flow": "winkle", + "page": "nautilus", } path = TransitionRouteGroupsClient.page_path(**expected) @@ -6618,10 +6663,10 @@ def test_parse_page_path(): def test_tool_path(): - project = "whelk" - location = "octopus" - agent = "oyster" - tool = "nudibranch" + project = "scallop" + location = "abalone" + agent = "squid" + tool = "clam" expected = ( "projects/{project}/locations/{location}/agents/{agent}/tools/{tool}".format( project=project, @@ -6636,10 +6681,10 @@ def test_tool_path(): def test_parse_tool_path(): expected = { - "project": "cuttlefish", - "location": "mussel", - "agent": "winkle", - "tool": "nautilus", + "project": "whelk", + "location": "octopus", + "agent": "oyster", + "tool": "nudibranch", } path = TransitionRouteGroupsClient.tool_path(**expected) @@ -6649,11 +6694,11 @@ def test_parse_tool_path(): def test_transition_route_group_path(): - project = "scallop" - location = "abalone" - agent = "squid" - flow = "clam" - transition_route_group = "whelk" + project = "cuttlefish" + location = "mussel" + agent = "winkle" + flow = "nautilus" + transition_route_group = "scallop" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/transitionRouteGroups/{transition_route_group}".format( project=project, location=location, @@ -6669,11 +6714,11 @@ def test_transition_route_group_path(): def test_parse_transition_route_group_path(): expected = { - "project": "octopus", - "location": "oyster", - "agent": "nudibranch", - "flow": "cuttlefish", - "transition_route_group": "mussel", + "project": "abalone", + "location": "squid", + "agent": "clam", + "flow": "whelk", + "transition_route_group": "octopus", } path = TransitionRouteGroupsClient.transition_route_group_path(**expected) @@ -6683,10 +6728,10 @@ def test_parse_transition_route_group_path(): def test_webhook_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - webhook = "abalone" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + webhook = "mussel" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -6699,10 +6744,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "webhook": "octopus", + "project": "winkle", + "location": "nautilus", + "agent": "scallop", + "webhook": "abalone", } path = TransitionRouteGroupsClient.webhook_path(**expected) @@ -6712,7 +6757,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "squid" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -6722,7 +6767,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "clam", } path = TransitionRouteGroupsClient.common_billing_account_path(**expected) @@ -6732,7 +6777,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "whelk" expected = "folders/{folder}".format( folder=folder, ) @@ -6742,7 +6787,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "octopus", } path = TransitionRouteGroupsClient.common_folder_path(**expected) @@ -6752,7 +6797,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "oyster" expected = "organizations/{organization}".format( organization=organization, ) @@ -6762,7 +6807,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "nudibranch", } path = TransitionRouteGroupsClient.common_organization_path(**expected) @@ -6772,7 +6817,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "cuttlefish" expected = "projects/{project}".format( project=project, ) @@ -6782,7 +6827,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "mussel", } path = TransitionRouteGroupsClient.common_project_path(**expected) @@ -6792,8 +6837,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "winkle" + location = "nautilus" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -6804,8 +6849,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "scallop", + "location": "abalone", } path = TransitionRouteGroupsClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py index 26aadb8d628b..819080b743a3 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py @@ -4540,11 +4540,14 @@ def test_create_webhook_rest_call_success(request_type): "uri": "uri_value", "username": "username_value", "password": "password_value", + "secret_version_for_username_password": "secret_version_for_username_password_value", "request_headers": {}, + "secret_versions_for_request_headers": {}, "allowed_ca_certs": [b"allowed_ca_certs_blob1", b"allowed_ca_certs_blob2"], "oauth_config": { "client_id": "client_id_value", "client_secret": "client_secret_value", + "secret_version_for_client_secret": "secret_version_for_client_secret_value", "token_endpoint": "token_endpoint_value", "scopes": ["scopes_value1", "scopes_value2"], }, @@ -4769,11 +4772,14 @@ def test_update_webhook_rest_call_success(request_type): "uri": "uri_value", "username": "username_value", "password": "password_value", + "secret_version_for_username_password": "secret_version_for_username_password_value", "request_headers": {}, + "secret_versions_for_request_headers": {}, "allowed_ca_certs": [b"allowed_ca_certs_blob1", b"allowed_ca_certs_blob2"], "oauth_config": { "client_id": "client_id_value", "client_secret": "client_secret_value", + "secret_version_for_client_secret": "secret_version_for_client_secret_value", "token_endpoint": "token_endpoint_value", "scopes": ["scopes_value1", "scopes_value2"], }, @@ -5907,11 +5913,37 @@ def test_webhooks_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel -def test_service_path(): +def test_secret_version_path(): project = "squid" - location = "clam" - namespace = "whelk" - service = "octopus" + secret = "clam" + version = "whelk" + expected = "projects/{project}/secrets/{secret}/versions/{version}".format( + project=project, + secret=secret, + version=version, + ) + actual = WebhooksClient.secret_version_path(project, secret, version) + assert expected == actual + + +def test_parse_secret_version_path(): + expected = { + "project": "octopus", + "secret": "oyster", + "version": "nudibranch", + } + path = WebhooksClient.secret_version_path(**expected) + + # Check that the path construction is reversible. + actual = WebhooksClient.parse_secret_version_path(path) + assert expected == actual + + +def test_service_path(): + project = "cuttlefish" + location = "mussel" + namespace = "winkle" + service = "nautilus" expected = "projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}".format( project=project, location=location, @@ -5924,10 +5956,10 @@ def test_service_path(): def test_parse_service_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "namespace": "cuttlefish", - "service": "mussel", + "project": "scallop", + "location": "abalone", + "namespace": "squid", + "service": "clam", } path = WebhooksClient.service_path(**expected) @@ -5937,10 +5969,10 @@ def test_parse_service_path(): def test_webhook_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - webhook = "abalone" + project = "whelk" + location = "octopus" + agent = "oyster" + webhook = "nudibranch" expected = "projects/{project}/locations/{location}/agents/{agent}/webhooks/{webhook}".format( project=project, location=location, @@ -5953,10 +5985,10 @@ def test_webhook_path(): def test_parse_webhook_path(): expected = { - "project": "squid", - "location": "clam", - "agent": "whelk", - "webhook": "octopus", + "project": "cuttlefish", + "location": "mussel", + "agent": "winkle", + "webhook": "nautilus", } path = WebhooksClient.webhook_path(**expected) @@ -5966,7 +5998,7 @@ def test_parse_webhook_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "scallop" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -5976,7 +6008,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "abalone", } path = WebhooksClient.common_billing_account_path(**expected) @@ -5986,7 +6018,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "squid" expected = "folders/{folder}".format( folder=folder, ) @@ -5996,7 +6028,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "clam", } path = WebhooksClient.common_folder_path(**expected) @@ -6006,7 +6038,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "whelk" expected = "organizations/{organization}".format( organization=organization, ) @@ -6016,7 +6048,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "octopus", } path = WebhooksClient.common_organization_path(**expected) @@ -6026,7 +6058,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "oyster" expected = "projects/{project}".format( project=project, ) @@ -6036,7 +6068,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "nudibranch", } path = WebhooksClient.common_project_path(**expected) @@ -6046,8 +6078,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "cuttlefish" + location = "mussel" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -6058,8 +6090,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "winkle", + "location": "nautilus", } path = WebhooksClient.common_location_path(**expected)