diff --git a/google/cloud/dialogflowcx_v3beta1/__init__.py b/google/cloud/dialogflowcx_v3beta1/__init__.py index db4a67fb..b89fa426 100644 --- a/google/cloud/dialogflowcx_v3beta1/__init__.py +++ b/google/cloud/dialogflowcx_v3beta1/__init__.py @@ -73,14 +73,20 @@ from .types.entity_type import ListEntityTypesRequest from .types.entity_type import ListEntityTypesResponse from .types.entity_type import UpdateEntityTypeRequest +from .types.environment import ContinuousTestResult from .types.environment import CreateEnvironmentRequest from .types.environment import DeleteEnvironmentRequest from .types.environment import Environment from .types.environment import GetEnvironmentRequest +from .types.environment import ListContinuousTestResultsRequest +from .types.environment import ListContinuousTestResultsResponse from .types.environment import ListEnvironmentsRequest from .types.environment import ListEnvironmentsResponse from .types.environment import LookupEnvironmentHistoryRequest from .types.environment import LookupEnvironmentHistoryResponse +from .types.environment import RunContinuousTestMetadata +from .types.environment import RunContinuousTestRequest +from .types.environment import RunContinuousTestResponse from .types.environment import UpdateEnvironmentRequest from .types.experiment import CreateExperimentRequest from .types.experiment import DeleteExperimentRequest @@ -252,6 +258,7 @@ "BatchRunTestCasesResponse", "CalculateCoverageRequest", "CalculateCoverageResponse", + "ContinuousTestResult", "ConversationTurn", "CreateAgentRequest", "CreateEntityTypeRequest", @@ -333,6 +340,8 @@ "IntentsClient", "ListAgentsRequest", "ListAgentsResponse", + "ListContinuousTestResultsRequest", + "ListContinuousTestResultsResponse", "ListEntityTypesRequest", "ListEntityTypesResponse", "ListEnvironmentsRequest", @@ -377,6 +386,9 @@ "ResourceName", "ResponseMessage", "RestoreAgentRequest", + "RunContinuousTestMetadata", + "RunContinuousTestRequest", + "RunContinuousTestResponse", "RunTestCaseMetadata", "RunTestCaseRequest", "RunTestCaseResponse", diff --git a/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json b/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json index c8dd46f2..661610d7 100644 --- a/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json +++ b/google/cloud/dialogflowcx_v3beta1/gapic_metadata.json @@ -193,6 +193,11 @@ "get_environment" ] }, + "ListContinuousTestResults": { + "methods": [ + "list_continuous_test_results" + ] + }, "ListEnvironments": { "methods": [ "list_environments" @@ -203,6 +208,11 @@ "lookup_environment_history" ] }, + "RunContinuousTest": { + "methods": [ + "run_continuous_test" + ] + }, "UpdateEnvironment": { "methods": [ "update_environment" @@ -228,6 +238,11 @@ "get_environment" ] }, + "ListContinuousTestResults": { + "methods": [ + "list_continuous_test_results" + ] + }, "ListEnvironments": { "methods": [ "list_environments" @@ -238,6 +253,11 @@ "lookup_environment_history" ] }, + "RunContinuousTest": { + "methods": [ + "run_continuous_test" + ] + }, "UpdateEnvironment": { "methods": [ "update_environment" diff --git a/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py b/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py index 7f9c961c..dc94b16b 100644 --- a/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py +++ b/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py @@ -49,8 +49,18 @@ class EnvironmentsAsyncClient: DEFAULT_ENDPOINT = EnvironmentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + continuous_test_result_path = staticmethod( + EnvironmentsClient.continuous_test_result_path + ) + parse_continuous_test_result_path = staticmethod( + EnvironmentsClient.parse_continuous_test_result_path + ) environment_path = staticmethod(EnvironmentsClient.environment_path) parse_environment_path = staticmethod(EnvironmentsClient.parse_environment_path) + test_case_result_path = staticmethod(EnvironmentsClient.test_case_result_path) + parse_test_case_result_path = staticmethod( + EnvironmentsClient.parse_test_case_result_path + ) version_path = staticmethod(EnvironmentsClient.version_path) parse_version_path = staticmethod(EnvironmentsClient.parse_version_path) common_billing_account_path = staticmethod( @@ -691,6 +701,151 @@ async def lookup_environment_history( # Done; return the response. return response + async def run_continuous_test( + self, + request: environment.RunContinuousTestRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Kicks off a continuous test under the specified + [Environment][google.cloud.dialogflow.cx.v3beta1.Environment]. + + Args: + request (:class:`google.cloud.dialogflowcx_v3beta1.types.RunContinuousTestRequest`): + The request object. The request message for + [Environments.RunContinuousTest][google.cloud.dialogflow.cx.v3beta1.Environments.RunContinuousTest]. + 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, str]]): Strings which should be + sent along with the request as metadata. + + 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.RunContinuousTestResponse` + The response message for + [Environments.RunContinuousTest][google.cloud.dialogflow.cx.v3beta1.Environments.RunContinuousTest]. + + """ + # Create or coerce a protobuf request object. + request = environment.RunContinuousTestRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.run_continuous_test, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("environment", request.environment),) + ), + ) + + # 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, + environment.RunContinuousTestResponse, + metadata_type=environment.RunContinuousTestMetadata, + ) + + # Done; return the response. + return response + + async def list_continuous_test_results( + self, + request: environment.ListContinuousTestResultsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListContinuousTestResultsAsyncPager: + r"""Fetches a list of continuous test results for a given + environment. + + Args: + request (:class:`google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsRequest`): + The request object. The request message for + [Environments.ListContinuousTestResults][google.cloud.dialogflow.cx.v3beta1.Environments.ListContinuousTestResults]. + parent (:class:`str`): + Required. The environment to list results for. Format: + ``projects//locations//agents// environments/``. + + This corresponds to the ``parent`` 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, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.dialogflowcx_v3beta1.services.environments.pagers.ListContinuousTestResultsAsyncPager: + The response message for + [Environments.ListTestCaseResults][]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = environment.ListContinuousTestResultsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_continuous_test_results, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListContinuousTestResultsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/dialogflowcx_v3beta1/services/environments/client.py b/google/cloud/dialogflowcx_v3beta1/services/environments/client.py index a3ec88d7..9fc5a264 100644 --- a/google/cloud/dialogflowcx_v3beta1/services/environments/client.py +++ b/google/cloud/dialogflowcx_v3beta1/services/environments/client.py @@ -161,6 +161,32 @@ def transport(self) -> EnvironmentsTransport: """ return self._transport + @staticmethod + def continuous_test_result_path( + project: str, + location: str, + agent: str, + environment: str, + continuous_test_result: str, + ) -> str: + """Returns a fully-qualified continuous_test_result string.""" + return "projects/{project}/locations/{location}/agents/{agent}/environments/{environment}/continuousTestResults/{continuous_test_result}".format( + project=project, + location=location, + agent=agent, + environment=environment, + continuous_test_result=continuous_test_result, + ) + + @staticmethod + def parse_continuous_test_result_path(path: str) -> Dict[str, str]: + """Parses a continuous_test_result path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/environments/(?P.+?)/continuousTestResults/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def environment_path( project: str, location: str, agent: str, environment: str, @@ -179,6 +205,28 @@ def parse_environment_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def test_case_result_path( + project: str, location: str, agent: str, test_case: str, result: str, + ) -> str: + """Returns a fully-qualified test_case_result string.""" + return "projects/{project}/locations/{location}/agents/{agent}/testCases/{test_case}/results/{result}".format( + project=project, + location=location, + agent=agent, + test_case=test_case, + result=result, + ) + + @staticmethod + def parse_test_case_result_path(path: str) -> Dict[str, str]: + """Parses a test_case_result path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/agents/(?P.+?)/testCases/(?P.+?)/results/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def version_path( project: str, location: str, agent: str, flow: str, version: str, @@ -898,6 +946,154 @@ def lookup_environment_history( # Done; return the response. return response + def run_continuous_test( + self, + request: environment.RunContinuousTestRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Kicks off a continuous test under the specified + [Environment][google.cloud.dialogflow.cx.v3beta1.Environment]. + + Args: + request (google.cloud.dialogflowcx_v3beta1.types.RunContinuousTestRequest): + The request object. The request message for + [Environments.RunContinuousTest][google.cloud.dialogflow.cx.v3beta1.Environments.RunContinuousTest]. + 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, str]]): Strings which should be + sent along with the request as metadata. + + 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.RunContinuousTestResponse` + The response message for + [Environments.RunContinuousTest][google.cloud.dialogflow.cx.v3beta1.Environments.RunContinuousTest]. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a environment.RunContinuousTestRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, environment.RunContinuousTestRequest): + request = environment.RunContinuousTestRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.run_continuous_test] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("environment", request.environment),) + ), + ) + + # 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, + environment.RunContinuousTestResponse, + metadata_type=environment.RunContinuousTestMetadata, + ) + + # Done; return the response. + return response + + def list_continuous_test_results( + self, + request: environment.ListContinuousTestResultsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListContinuousTestResultsPager: + r"""Fetches a list of continuous test results for a given + environment. + + Args: + request (google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsRequest): + The request object. The request message for + [Environments.ListContinuousTestResults][google.cloud.dialogflow.cx.v3beta1.Environments.ListContinuousTestResults]. + parent (str): + Required. The environment to list results for. Format: + ``projects//locations//agents// environments/``. + + This corresponds to the ``parent`` 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, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.dialogflowcx_v3beta1.services.environments.pagers.ListContinuousTestResultsPager: + The response message for + [Environments.ListTestCaseResults][]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a environment.ListContinuousTestResultsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, environment.ListContinuousTestResultsRequest): + request = environment.ListContinuousTestResultsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.list_continuous_test_results + ] + + # 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),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListContinuousTestResultsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/dialogflowcx_v3beta1/services/environments/pagers.py b/google/cloud/dialogflowcx_v3beta1/services/environments/pagers.py index 53d80e94..7a03d756 100644 --- a/google/cloud/dialogflowcx_v3beta1/services/environments/pagers.py +++ b/google/cloud/dialogflowcx_v3beta1/services/environments/pagers.py @@ -283,3 +283,133 @@ async def async_generator(): def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListContinuousTestResultsPager: + """A pager for iterating through ``list_continuous_test_results`` requests. + + This class thinly wraps an initial + :class:`google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``continuous_test_results`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListContinuousTestResults`` requests and continue to iterate + through the ``continuous_test_results`` field on the + corresponding responses. + + All the usual :class:`google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., environment.ListContinuousTestResultsResponse], + request: environment.ListContinuousTestResultsRequest, + response: environment.ListContinuousTestResultsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsRequest): + The initial request object. + response (google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = environment.ListContinuousTestResultsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterable[environment.ListContinuousTestResultsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterable[environment.ContinuousTestResult]: + for page in self.pages: + yield from page.continuous_test_results + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListContinuousTestResultsAsyncPager: + """A pager for iterating through ``list_continuous_test_results`` requests. + + This class thinly wraps an initial + :class:`google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``continuous_test_results`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListContinuousTestResults`` requests and continue to iterate + through the ``continuous_test_results`` field on the + corresponding responses. + + All the usual :class:`google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[environment.ListContinuousTestResultsResponse]], + request: environment.ListContinuousTestResultsRequest, + response: environment.ListContinuousTestResultsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsRequest): + The initial request object. + response (google.cloud.dialogflowcx_v3beta1.types.ListContinuousTestResultsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = environment.ListContinuousTestResultsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterable[environment.ListContinuousTestResultsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterable[environment.ContinuousTestResult]: + async def async_generator(): + async for page in self.pages: + for response in page.continuous_test_results: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py b/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py index 8ddda462..697d55f9 100644 --- a/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py +++ b/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py @@ -193,6 +193,14 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.run_continuous_test: gapic_v1.method.wrap_method( + self.run_continuous_test, default_timeout=None, client_info=client_info, + ), + self.list_continuous_test_results: gapic_v1.method.wrap_method( + self.list_continuous_test_results, + default_timeout=None, + client_info=client_info, + ), } @property @@ -260,5 +268,26 @@ def lookup_environment_history( ]: raise NotImplementedError() + @property + def run_continuous_test( + self, + ) -> Callable[ + [environment.RunContinuousTestRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def list_continuous_test_results( + self, + ) -> Callable[ + [environment.ListContinuousTestResultsRequest], + Union[ + environment.ListContinuousTestResultsResponse, + Awaitable[environment.ListContinuousTestResultsResponse], + ], + ]: + raise NotImplementedError() + __all__ = ("EnvironmentsTransport",) diff --git a/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py b/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py index 01aac0ae..6d0a6c9a 100644 --- a/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py +++ b/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py @@ -413,5 +413,62 @@ def lookup_environment_history( ) return self._stubs["lookup_environment_history"] + @property + def run_continuous_test( + self, + ) -> Callable[[environment.RunContinuousTestRequest], operations_pb2.Operation]: + r"""Return a callable for the run continuous test method over gRPC. + + Kicks off a continuous test under the specified + [Environment][google.cloud.dialogflow.cx.v3beta1.Environment]. + + Returns: + Callable[[~.RunContinuousTestRequest], + ~.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 "run_continuous_test" not in self._stubs: + self._stubs["run_continuous_test"] = self.grpc_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Environments/RunContinuousTest", + request_serializer=environment.RunContinuousTestRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["run_continuous_test"] + + @property + def list_continuous_test_results( + self, + ) -> Callable[ + [environment.ListContinuousTestResultsRequest], + environment.ListContinuousTestResultsResponse, + ]: + r"""Return a callable for the list continuous test results method over gRPC. + + Fetches a list of continuous test results for a given + environment. + + Returns: + Callable[[~.ListContinuousTestResultsRequest], + ~.ListContinuousTestResultsResponse]: + 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 "list_continuous_test_results" not in self._stubs: + self._stubs["list_continuous_test_results"] = self.grpc_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Environments/ListContinuousTestResults", + request_serializer=environment.ListContinuousTestResultsRequest.serialize, + response_deserializer=environment.ListContinuousTestResultsResponse.deserialize, + ) + return self._stubs["list_continuous_test_results"] + __all__ = ("EnvironmentsGrpcTransport",) diff --git a/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py b/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py index 10474950..da9d3392 100644 --- a/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py +++ b/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py @@ -421,5 +421,64 @@ def lookup_environment_history( ) return self._stubs["lookup_environment_history"] + @property + def run_continuous_test( + self, + ) -> Callable[ + [environment.RunContinuousTestRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the run continuous test method over gRPC. + + Kicks off a continuous test under the specified + [Environment][google.cloud.dialogflow.cx.v3beta1.Environment]. + + Returns: + Callable[[~.RunContinuousTestRequest], + 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 "run_continuous_test" not in self._stubs: + self._stubs["run_continuous_test"] = self.grpc_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Environments/RunContinuousTest", + request_serializer=environment.RunContinuousTestRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["run_continuous_test"] + + @property + def list_continuous_test_results( + self, + ) -> Callable[ + [environment.ListContinuousTestResultsRequest], + Awaitable[environment.ListContinuousTestResultsResponse], + ]: + r"""Return a callable for the list continuous test results method over gRPC. + + Fetches a list of continuous test results for a given + environment. + + Returns: + Callable[[~.ListContinuousTestResultsRequest], + Awaitable[~.ListContinuousTestResultsResponse]]: + 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 "list_continuous_test_results" not in self._stubs: + self._stubs["list_continuous_test_results"] = self.grpc_channel.unary_unary( + "/google.cloud.dialogflow.cx.v3beta1.Environments/ListContinuousTestResults", + request_serializer=environment.ListContinuousTestResultsRequest.serialize, + response_deserializer=environment.ListContinuousTestResultsResponse.deserialize, + ) + return self._stubs["list_continuous_test_results"] + __all__ = ("EnvironmentsGrpcAsyncIOTransport",) diff --git a/google/cloud/dialogflowcx_v3beta1/types/__init__.py b/google/cloud/dialogflowcx_v3beta1/types/__init__.py index 00da5907..c083e5b6 100644 --- a/google/cloud/dialogflowcx_v3beta1/types/__init__.py +++ b/google/cloud/dialogflowcx_v3beta1/types/__init__.py @@ -50,14 +50,20 @@ UpdateEntityTypeRequest, ) from .environment import ( + ContinuousTestResult, CreateEnvironmentRequest, DeleteEnvironmentRequest, Environment, GetEnvironmentRequest, + ListContinuousTestResultsRequest, + ListContinuousTestResultsResponse, ListEnvironmentsRequest, ListEnvironmentsResponse, LookupEnvironmentHistoryRequest, LookupEnvironmentHistoryResponse, + RunContinuousTestMetadata, + RunContinuousTestRequest, + RunContinuousTestResponse, UpdateEnvironmentRequest, ) from .experiment import ( @@ -259,14 +265,20 @@ "ListEntityTypesRequest", "ListEntityTypesResponse", "UpdateEntityTypeRequest", + "ContinuousTestResult", "CreateEnvironmentRequest", "DeleteEnvironmentRequest", "Environment", "GetEnvironmentRequest", + "ListContinuousTestResultsRequest", + "ListContinuousTestResultsResponse", "ListEnvironmentsRequest", "ListEnvironmentsResponse", "LookupEnvironmentHistoryRequest", "LookupEnvironmentHistoryResponse", + "RunContinuousTestMetadata", + "RunContinuousTestRequest", + "RunContinuousTestResponse", "UpdateEnvironmentRequest", "CreateExperimentRequest", "DeleteExperimentRequest", diff --git a/google/cloud/dialogflowcx_v3beta1/types/environment.py b/google/cloud/dialogflowcx_v3beta1/types/environment.py index f48c77a9..4d47818d 100644 --- a/google/cloud/dialogflowcx_v3beta1/types/environment.py +++ b/google/cloud/dialogflowcx_v3beta1/types/environment.py @@ -15,6 +15,7 @@ # import proto # type: ignore +from google.cloud.dialogflowcx_v3beta1.types import test_case from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -31,6 +32,12 @@ "DeleteEnvironmentRequest", "LookupEnvironmentHistoryRequest", "LookupEnvironmentHistoryResponse", + "ContinuousTestResult", + "RunContinuousTestRequest", + "RunContinuousTestResponse", + "RunContinuousTestMetadata", + "ListContinuousTestResultsRequest", + "ListContinuousTestResultsResponse", }, ) @@ -248,4 +255,119 @@ def raw_page(self): next_page_token = proto.Field(proto.STRING, number=2,) +class ContinuousTestResult(proto.Message): + r"""Represents a result from running a test case in an agent + environment. + + Attributes: + name (str): + The resource name for the continuous test result. Format: + ``projects//locations//agents//environments//continuousTestResults/``. + result (google.cloud.dialogflowcx_v3beta1.types.ContinuousTestResult.AggregatedTestResult): + The result of this continuous test run, i.e. + whether all the tests in this continuous test + run pass or not. + test_case_results (Sequence[str]): + A list of individual test case results names + in this continuous test run. + run_time (google.protobuf.timestamp_pb2.Timestamp): + Time when the continuous testing run starts. + """ + + class AggregatedTestResult(proto.Enum): + r"""The overall result for a continuous test run in an agent + environment. + """ + AGGREGATED_TEST_RESULT_UNSPECIFIED = 0 + PASSED = 1 + FAILED = 2 + + name = proto.Field(proto.STRING, number=1,) + result = proto.Field(proto.ENUM, number=2, enum=AggregatedTestResult,) + test_case_results = proto.RepeatedField(proto.STRING, number=3,) + run_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + + +class RunContinuousTestRequest(proto.Message): + r"""The request message for + [Environments.RunContinuousTest][google.cloud.dialogflow.cx.v3beta1.Environments.RunContinuousTest]. + + Attributes: + environment (str): + Required. Format: + ``projects//locations//agents//environments/``. + """ + + environment = proto.Field(proto.STRING, number=1,) + + +class RunContinuousTestResponse(proto.Message): + r"""The response message for + [Environments.RunContinuousTest][google.cloud.dialogflow.cx.v3beta1.Environments.RunContinuousTest]. + + Attributes: + continuous_test_result (google.cloud.dialogflowcx_v3beta1.types.ContinuousTestResult): + The result for a continuous test run. + """ + + continuous_test_result = proto.Field( + proto.MESSAGE, number=1, message="ContinuousTestResult", + ) + + +class RunContinuousTestMetadata(proto.Message): + r"""Metadata returned for the + [Environments.RunContinuousTest][google.cloud.dialogflow.cx.v3beta1.Environments.RunContinuousTest] + long running operation. + + Attributes: + errors (Sequence[google.cloud.dialogflowcx_v3beta1.types.TestError]): + The test errors. + """ + + errors = proto.RepeatedField(proto.MESSAGE, number=1, message=test_case.TestError,) + + +class ListContinuousTestResultsRequest(proto.Message): + r"""The request message for + [Environments.ListContinuousTestResults][google.cloud.dialogflow.cx.v3beta1.Environments.ListContinuousTestResults]. + + Attributes: + parent (str): + Required. The environment to list results for. Format: + ``projects//locations//agents// environments/``. + page_size (int): + The maximum number of items to return in a + single page. By default 100 and at most 1000. + page_token (str): + The next_page_token value returned from a previous list + request. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + + +class ListContinuousTestResultsResponse(proto.Message): + r"""The response message for [Environments.ListTestCaseResults][]. + Attributes: + continuous_test_results (Sequence[google.cloud.dialogflowcx_v3beta1.types.ContinuousTestResult]): + The list of continuous test results. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + continuous_test_results = proto.RepeatedField( + proto.MESSAGE, number=1, message="ContinuousTestResult", + ) + next_page_token = proto.Field(proto.STRING, number=2,) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py b/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py index 44ff5fbf..fd6bc8a6 100644 --- a/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py +++ b/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py @@ -2061,6 +2061,533 @@ async def test_lookup_environment_history_async_pages(): assert page_.raw_page.next_page_token == token +def test_run_continuous_test( + transport: str = "grpc", request_type=environment.RunContinuousTestRequest +): + client = EnvironmentsClient( + 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.run_continuous_test), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.run_continuous_test(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == environment.RunContinuousTestRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_run_continuous_test_from_dict(): + test_run_continuous_test(request_type=dict) + + +def test_run_continuous_test_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.run_continuous_test), "__call__" + ) as call: + client.run_continuous_test() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == environment.RunContinuousTestRequest() + + +@pytest.mark.asyncio +async def test_run_continuous_test_async( + transport: str = "grpc_asyncio", request_type=environment.RunContinuousTestRequest +): + client = EnvironmentsAsyncClient( + 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.run_continuous_test), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.run_continuous_test(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == environment.RunContinuousTestRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_run_continuous_test_async_from_dict(): + await test_run_continuous_test_async(request_type=dict) + + +def test_run_continuous_test_field_headers(): + client = EnvironmentsClient(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 = environment.RunContinuousTestRequest() + + request.environment = "environment/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.run_continuous_test), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.run_continuous_test(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", "environment=environment/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_run_continuous_test_field_headers_async(): + client = EnvironmentsAsyncClient(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 = environment.RunContinuousTestRequest() + + request.environment = "environment/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.run_continuous_test), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.run_continuous_test(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", "environment=environment/value",) in kw["metadata"] + + +def test_list_continuous_test_results( + transport: str = "grpc", request_type=environment.ListContinuousTestResultsRequest +): + client = EnvironmentsClient( + 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_continuous_test_results), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = environment.ListContinuousTestResultsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_continuous_test_results(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == environment.ListContinuousTestResultsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListContinuousTestResultsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_continuous_test_results_from_dict(): + test_list_continuous_test_results(request_type=dict) + + +def test_list_continuous_test_results_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), "__call__" + ) as call: + client.list_continuous_test_results() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == environment.ListContinuousTestResultsRequest() + + +@pytest.mark.asyncio +async def test_list_continuous_test_results_async( + transport: str = "grpc_asyncio", + request_type=environment.ListContinuousTestResultsRequest, +): + client = EnvironmentsAsyncClient( + 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_continuous_test_results), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + environment.ListContinuousTestResultsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_continuous_test_results(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == environment.ListContinuousTestResultsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListContinuousTestResultsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_continuous_test_results_async_from_dict(): + await test_list_continuous_test_results_async(request_type=dict) + + +def test_list_continuous_test_results_field_headers(): + client = EnvironmentsClient(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 = environment.ListContinuousTestResultsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), "__call__" + ) as call: + call.return_value = environment.ListContinuousTestResultsResponse() + client.list_continuous_test_results(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_continuous_test_results_field_headers_async(): + client = EnvironmentsAsyncClient(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 = environment.ListContinuousTestResultsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + environment.ListContinuousTestResultsResponse() + ) + await client.list_continuous_test_results(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_continuous_test_results_flattened(): + client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = environment.ListContinuousTestResultsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_continuous_test_results(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] + assert args[0].parent == "parent_value" + + +def test_list_continuous_test_results_flattened_error(): + client = EnvironmentsClient(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_continuous_test_results( + environment.ListContinuousTestResultsRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_continuous_test_results_flattened_async(): + client = EnvironmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = environment.ListContinuousTestResultsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + environment.ListContinuousTestResultsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_continuous_test_results(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] + assert args[0].parent == "parent_value" + + +@pytest.mark.asyncio +async def test_list_continuous_test_results_flattened_error_async(): + client = EnvironmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_continuous_test_results( + environment.ListContinuousTestResultsRequest(), parent="parent_value", + ) + + +def test_list_continuous_test_results_pager(): + client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + next_page_token="abc", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[], next_page_token="def", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[environment.ContinuousTestResult(),], + next_page_token="ghi", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_continuous_test_results(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, environment.ContinuousTestResult) for i in results) + + +def test_list_continuous_test_results_pages(): + client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + next_page_token="abc", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[], next_page_token="def", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[environment.ContinuousTestResult(),], + next_page_token="ghi", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + ), + RuntimeError, + ) + pages = list(client.list_continuous_test_results(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_continuous_test_results_async_pager(): + client = EnvironmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + next_page_token="abc", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[], next_page_token="def", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[environment.ContinuousTestResult(),], + next_page_token="ghi", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_continuous_test_results(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, environment.ContinuousTestResult) for i in responses) + + +@pytest.mark.asyncio +async def test_list_continuous_test_results_async_pages(): + client = EnvironmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_continuous_test_results), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + next_page_token="abc", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[], next_page_token="def", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[environment.ContinuousTestResult(),], + next_page_token="ghi", + ), + environment.ListContinuousTestResultsResponse( + continuous_test_results=[ + environment.ContinuousTestResult(), + environment.ContinuousTestResult(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_continuous_test_results(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EnvironmentsGrpcTransport( @@ -2164,6 +2691,8 @@ def test_environments_base_transport(): "update_environment", "delete_environment", "lookup_environment_history", + "run_continuous_test", + "list_continuous_test_results", ) for method in methods: with pytest.raises(NotImplementedError): @@ -2639,11 +3168,45 @@ def test_environments_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_environment_path(): +def test_continuous_test_result_path(): project = "squid" location = "clam" agent = "whelk" environment = "octopus" + continuous_test_result = "oyster" + expected = "projects/{project}/locations/{location}/agents/{agent}/environments/{environment}/continuousTestResults/{continuous_test_result}".format( + project=project, + location=location, + agent=agent, + environment=environment, + continuous_test_result=continuous_test_result, + ) + actual = EnvironmentsClient.continuous_test_result_path( + project, location, agent, environment, continuous_test_result + ) + assert expected == actual + + +def test_parse_continuous_test_result_path(): + expected = { + "project": "nudibranch", + "location": "cuttlefish", + "agent": "mussel", + "environment": "winkle", + "continuous_test_result": "nautilus", + } + path = EnvironmentsClient.continuous_test_result_path(**expected) + + # Check that the path construction is reversible. + actual = EnvironmentsClient.parse_continuous_test_result_path(path) + assert expected == actual + + +def test_environment_path(): + project = "scallop" + location = "abalone" + agent = "squid" + environment = "clam" expected = "projects/{project}/locations/{location}/agents/{agent}/environments/{environment}".format( project=project, location=location, agent=agent, environment=environment, ) @@ -2653,10 +3216,10 @@ def test_environment_path(): def test_parse_environment_path(): expected = { - "project": "oyster", - "location": "nudibranch", - "agent": "cuttlefish", - "environment": "mussel", + "project": "whelk", + "location": "octopus", + "agent": "oyster", + "environment": "nudibranch", } path = EnvironmentsClient.environment_path(**expected) @@ -2665,12 +3228,46 @@ def test_parse_environment_path(): assert expected == actual +def test_test_case_result_path(): + project = "cuttlefish" + location = "mussel" + agent = "winkle" + test_case = "nautilus" + result = "scallop" + expected = "projects/{project}/locations/{location}/agents/{agent}/testCases/{test_case}/results/{result}".format( + project=project, + location=location, + agent=agent, + test_case=test_case, + result=result, + ) + actual = EnvironmentsClient.test_case_result_path( + project, location, agent, test_case, result + ) + assert expected == actual + + +def test_parse_test_case_result_path(): + expected = { + "project": "abalone", + "location": "squid", + "agent": "clam", + "test_case": "whelk", + "result": "octopus", + } + path = EnvironmentsClient.test_case_result_path(**expected) + + # Check that the path construction is reversible. + actual = EnvironmentsClient.parse_test_case_result_path(path) + assert expected == actual + + def test_version_path(): - project = "winkle" - location = "nautilus" - agent = "scallop" - flow = "abalone" - version = "squid" + project = "oyster" + location = "nudibranch" + agent = "cuttlefish" + flow = "mussel" + version = "winkle" expected = "projects/{project}/locations/{location}/agents/{agent}/flows/{flow}/versions/{version}".format( project=project, location=location, agent=agent, flow=flow, version=version, ) @@ -2680,11 +3277,11 @@ def test_version_path(): def test_parse_version_path(): expected = { - "project": "clam", - "location": "whelk", - "agent": "octopus", - "flow": "oyster", - "version": "nudibranch", + "project": "nautilus", + "location": "scallop", + "agent": "abalone", + "flow": "squid", + "version": "clam", } path = EnvironmentsClient.version_path(**expected) @@ -2694,7 +3291,7 @@ def test_parse_version_path(): def test_common_billing_account_path(): - billing_account = "cuttlefish" + billing_account = "whelk" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2704,7 +3301,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "mussel", + "billing_account": "octopus", } path = EnvironmentsClient.common_billing_account_path(**expected) @@ -2714,7 +3311,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "winkle" + folder = "oyster" expected = "folders/{folder}".format(folder=folder,) actual = EnvironmentsClient.common_folder_path(folder) assert expected == actual @@ -2722,7 +3319,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "nautilus", + "folder": "nudibranch", } path = EnvironmentsClient.common_folder_path(**expected) @@ -2732,7 +3329,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "scallop" + organization = "cuttlefish" expected = "organizations/{organization}".format(organization=organization,) actual = EnvironmentsClient.common_organization_path(organization) assert expected == actual @@ -2740,7 +3337,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "abalone", + "organization": "mussel", } path = EnvironmentsClient.common_organization_path(**expected) @@ -2750,7 +3347,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "squid" + project = "winkle" expected = "projects/{project}".format(project=project,) actual = EnvironmentsClient.common_project_path(project) assert expected == actual @@ -2758,7 +3355,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "clam", + "project": "nautilus", } path = EnvironmentsClient.common_project_path(**expected) @@ -2768,8 +3365,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "whelk" - location = "octopus" + project = "scallop" + location = "abalone" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -2779,8 +3376,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "oyster", - "location": "nudibranch", + "project": "squid", + "location": "clam", } path = EnvironmentsClient.common_location_path(**expected)