async def test_annotate_video_async( transport: str = "grpc_asyncio", request_type=video_intelligence.AnnotateVideoRequest, ): client = VideoIntelligenceServiceAsyncClient( 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.annotate_video), "__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.annotate_video(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] assert args[0] == video_intelligence.AnnotateVideoRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future)
async def test_annotate_video_flattened_error_async(): client = VideoIntelligenceServiceAsyncClient( 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.annotate_video( video_intelligence.AnnotateVideoRequest(), input_uri="input_uri_value", features=[video_intelligence.Feature.LABEL_DETECTION], )
def test_annotate_video_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 = VideoIntelligenceServiceClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.annotate_video), "__call__") as call: client.annotate_video() call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == video_intelligence.AnnotateVideoRequest()
async def annotate_video( self, request: video_intelligence.AnnotateVideoRequest = None, *, input_uri: str = None, features: Sequence[video_intelligence.Feature] = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Performs asynchronous video annotation. Progress and results can be retrieved through the ``google.longrunning.Operations`` interface. ``Operation.metadata`` contains ``AnnotateVideoProgress`` (progress). ``Operation.response`` contains ``AnnotateVideoResponse`` (results). Args: request (:class:`google.cloud.videointelligence_v1.types.AnnotateVideoRequest`): The request object. Video annotation request. input_uri (:class:`str`): Input video location. Currently, only `Cloud Storage <https://cloud.google.com/storage/>`__ URIs are supported. URIs must be specified in the following format: ``gs://bucket-id/object-id`` (other URI formats return [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see `Request URIs <https://cloud.google.com/storage/docs/request-endpoints>`__. To identify multiple videos, a video URI may include wildcards in the ``object-id``. Supported wildcards: '*' to match 0 or more characters; '?' to match 1 character. If unset, the input video should be embedded in the request as ``input_content``. If set, ``input_content`` must be unset. This corresponds to the ``input_uri`` field on the ``request`` instance; if ``request`` is provided, this should not be set. features (:class:`Sequence[google.cloud.videointelligence_v1.types.Feature]`): Required. Requested video annotation features. This corresponds to the ``features`` 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.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be :class:`google.cloud.videointelligence_v1.types.AnnotateVideoResponse` Video annotation response. Included in the response field of the Operation returned by the GetOperation call of the google::longrunning::Operations service. """ # 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([input_uri, features]) 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 = video_intelligence.AnnotateVideoRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if input_uri is not None: request.input_uri = input_uri if features: request.features.extend(features) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.annotate_video, default_retry=retries.Retry( initial=1.0, maximum=120.0, multiplier=2.5, predicate=retries.if_exception_type( core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), deadline=600.0, ), default_timeout=600.0, client_info=DEFAULT_CLIENT_INFO, ) # 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, video_intelligence.AnnotateVideoResponse, metadata_type=video_intelligence.AnnotateVideoProgress, ) # Done; return the response. return response