def test_annotate_video(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = video_intelligence_pb2.AnnotateVideoResponse(
            **expected_response
        )
        operation = operations_pb2.Operation(
            name="operations/test_annotate_video", done=True
        )
        operation.response.Pack(expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = videointelligence_v1beta1.VideoIntelligenceServiceClient()

        # Setup Request
        input_uri = "gs://demomaker/cat.mp4"
        features_element = enums.Feature.LABEL_DETECTION
        features = [features_element]

        response = client.annotate_video(input_uri, features)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = video_intelligence_pb2.AnnotateVideoRequest(
            input_uri=input_uri, features=features
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 2
0
    def test_annotate_video(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = video_intelligence_pb2.AnnotateVideoResponse(
            **expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_annotate_video', done=True)
        operation.response.Pack(expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = videointelligence_v1beta1.VideoIntelligenceServiceClient(
            channel=channel)

        # Setup Request
        input_uri = 'gs://demomaker/cat.mp4'
        features_element = enums.Feature.LABEL_DETECTION
        features = [features_element]

        response = client.annotate_video(input_uri, features)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = video_intelligence_pb2.AnnotateVideoRequest(
            input_uri=input_uri, features=features)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 3
0
    def test_annotate_video(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = videointelligence_v1beta1.VideoIntelligenceServiceClient()

        # Mock request
        input_uri = 'inputUri1707300727'
        features = []

        # Mock response
        expected_response = {}
        expected_response = video_intelligence_pb2.AnnotateVideoResponse(
            **expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_annotate_video', done=True)
        operation.response.Pack(expected_response)
        grpc_stub.AnnotateVideo.return_value = operation

        response = client.annotate_video(input_uri, features)
        self.assertEqual(expected_response, response.result())

        grpc_stub.AnnotateVideo.assert_called_once()
        args, kwargs = grpc_stub.AnnotateVideo.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = video_intelligence_pb2.AnnotateVideoRequest(
            input_uri=input_uri, features=features)
        self.assertEqual(expected_request, actual_request)
Exemplo n.º 4
0
    def test_annotate_video_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_annotate_video_exception', done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = videointelligence_v1beta1.VideoIntelligenceServiceClient(
            channel=channel)

        # Setup Request
        input_uri = 'gs://demomaker/cat.mp4'
        features_element = enums.Feature.LABEL_DETECTION
        features = [features_element]

        response = client.annotate_video(input_uri, features)
        exception = response.exception()
        assert exception.errors[0] == error
Exemplo n.º 5
0
    def test_annotate_video_exception(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = videointelligence_v1beta1.VideoIntelligenceServiceClient()

        # Mock request
        input_uri = 'inputUri1707300727'
        features = []

        # Mock exception response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_annotate_video_exception', done=True)
        operation.error.CopyFrom(error)
        grpc_stub.AnnotateVideo.return_value = operation

        response = client.annotate_video(input_uri, features)
        self.assertEqual(error, response.exception())
    def test_annotate_video_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_annotate_video_exception", done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = videointelligence_v1beta1.VideoIntelligenceServiceClient()

        # Setup Request
        input_uri = "gs://demomaker/cat.mp4"
        features_element = enums.Feature.LABEL_DETECTION
        features = [features_element]

        response = client.annotate_video(input_uri, features)
        exception = response.exception()
        assert exception.errors[0] == error