async def test_synthesize_speech_flattened_async():
    client = TextToSpeechAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.synthesize_speech),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = cloud_tts.SynthesizeSpeechResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            cloud_tts.SynthesizeSpeechResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.synthesize_speech(
            input=cloud_tts.SynthesisInput(text="text_value"),
            voice=cloud_tts.VoiceSelectionParams(
                language_code="language_code_value"),
            audio_config=cloud_tts.AudioConfig(
                audio_encoding=cloud_tts.AudioEncoding.LINEAR16),
        )

        # 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].input == cloud_tts.SynthesisInput(text="text_value")

        assert args[0].voice == cloud_tts.VoiceSelectionParams(
            language_code="language_code_value")

        assert args[0].audio_config == cloud_tts.AudioConfig(
            audio_encoding=cloud_tts.AudioEncoding.LINEAR16)
Ejemplo n.º 2
0
def test_synthesize_speech_flattened_error():
    client = TextToSpeechClient(credentials=credentials.AnonymousCredentials())

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        client.synthesize_speech(
            cloud_tts.SynthesizeSpeechRequest(),
            input=cloud_tts.SynthesisInput(text="text_value"),
            voice=cloud_tts.VoiceSelectionParams(
                language_code="language_code_value"),
            audio_config=cloud_tts.AudioConfig(
                audio_encoding=cloud_tts.AudioEncoding.LINEAR16),
        )