예제 #1
0
    def test_cancel_issues_call_when_not_done(self):
        operation = self._make_operation()

        fake_client = _FakeOperationsClient([operation])
        fake_client.cancel_operation = mock.Mock()

        operation_future = _OperationFuture(operation, fake_client, Simple,
                                            Simple)

        self.assertTrue(operation_future.cancel())
        fake_client.cancel_operation.assert_called_with(self.OPERATION_NAME)
예제 #2
0
    def test_cancel_does_nothing_when_already_done(self):
        operation = self._make_operation(done=True)

        fake_client = _FakeOperationsClient([operation])
        fake_client.cancel_operation = mock.Mock()

        operation_future = _OperationFuture(operation, fake_client, Simple,
                                            Simple)

        self.assertFalse(operation_future.cancel())
        fake_client.cancel_operation.assert_not_called()
예제 #3
0
    def long_running_recognize(self, config, audio):
        from google.gapic.longrunning.operations_client import OperationsClient
        from google.gax import _OperationFuture
        from google.longrunning.operations_pb2 import Operation
        from google.cloud.proto.speech.v1.cloud_speech_pb2 import (
            LongRunningRecognizeResponse)

        self.config = config
        self.audio = audio
        operations_client = mock.Mock(spec=OperationsClient)
        operation_future = _OperationFuture(Operation(), operations_client,
                                            LongRunningRecognizeResponse, {})
        return operation_future
예제 #4
0
    def _make_operation_future(self, *operations):
        if not operations:
            operations = [self._make_operation()]

        fake_client = _FakeOperationsClient(operations)
        return _OperationFuture(operations[0], fake_client, Simple, Simple)