diff --git a/google/cloud/translate_v3/services/translation_service/async_client.py b/google/cloud/translate_v3/services/translation_service/async_client.py index 6ce5fc70..d7a96c9e 100644 --- a/google/cloud/translate_v3/services/translation_service/async_client.py +++ b/google/cloud/translate_v3/services/translation_service/async_client.py @@ -707,6 +707,11 @@ async def batch_translate_document( self, request: translation_service.BatchTranslateDocumentRequest = None, *, + parent: str = None, + source_language_code: str = None, + target_language_codes: Sequence[str] = None, + input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, + output_config: translation_service.BatchDocumentOutputConfig = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -724,6 +729,63 @@ async def batch_translate_document( Args: request (:class:`google.cloud.translate_v3.types.BatchTranslateDocumentRequest`): The request object. The BatchTranslateDocument request. + parent (:class:`str`): + Required. Location to make a regional call. + + Format: + ``projects/{project-number-or-id}/locations/{location-id}``. + + The ``global`` location is not supported for batch + translation. + + Only AutoML Translation models or glossaries within the + same region (have the same location-id) can be used, + otherwise an INVALID_ARGUMENT (400) error is returned. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_language_code (:class:`str`): + Required. The BCP-47 language code of + the input document if known, for + example, "en-US" or "sr-Latn". Supported + language codes are listed in Language + Support + (https://cloud.google.com/translate/docs/languages). + + This corresponds to the ``source_language_code`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + target_language_codes (:class:`Sequence[str]`): + Required. The BCP-47 language code to + use for translation of the input + document. Specify up to 10 language + codes here. + + This corresponds to the ``target_language_codes`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_configs (:class:`Sequence[google.cloud.translate_v3.types.BatchDocumentInputConfig]`): + Required. Input configurations. + The total number of files matched should + be <= 100. The total content size to + translate should be <= 100M Unicode + codepoints. The files must use UTF-8 + encoding. + + This corresponds to the ``input_configs`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (:class:`google.cloud.translate_v3.types.BatchDocumentOutputConfig`): + Required. Output configuration. + If 2 input configs match to the same + file (that is, same input path), we + don't generate output for duplicate + inputs. + + This corresponds to the ``output_config`` 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. @@ -741,8 +803,38 @@ async def batch_translate_document( """ # 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, + source_language_code, + target_language_codes, + input_configs, + output_config, + ] + ) + 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 = translation_service.BatchTranslateDocumentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if source_language_code is not None: + request.source_language_code = source_language_code + if output_config is not None: + request.output_config = output_config + if target_language_codes: + request.target_language_codes.extend(target_language_codes) + if input_configs: + request.input_configs.extend(input_configs) + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( diff --git a/google/cloud/translate_v3/services/translation_service/client.py b/google/cloud/translate_v3/services/translation_service/client.py index 0816e3f6..2562b63a 100644 --- a/google/cloud/translate_v3/services/translation_service/client.py +++ b/google/cloud/translate_v3/services/translation_service/client.py @@ -886,6 +886,11 @@ def batch_translate_document( self, request: Union[translation_service.BatchTranslateDocumentRequest, dict] = None, *, + parent: str = None, + source_language_code: str = None, + target_language_codes: Sequence[str] = None, + input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, + output_config: translation_service.BatchDocumentOutputConfig = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -903,6 +908,63 @@ def batch_translate_document( Args: request (Union[google.cloud.translate_v3.types.BatchTranslateDocumentRequest, dict]): The request object. The BatchTranslateDocument request. + parent (str): + Required. Location to make a regional call. + + Format: + ``projects/{project-number-or-id}/locations/{location-id}``. + + The ``global`` location is not supported for batch + translation. + + Only AutoML Translation models or glossaries within the + same region (have the same location-id) can be used, + otherwise an INVALID_ARGUMENT (400) error is returned. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_language_code (str): + Required. The BCP-47 language code of + the input document if known, for + example, "en-US" or "sr-Latn". Supported + language codes are listed in Language + Support + (https://cloud.google.com/translate/docs/languages). + + This corresponds to the ``source_language_code`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + target_language_codes (Sequence[str]): + Required. The BCP-47 language code to + use for translation of the input + document. Specify up to 10 language + codes here. + + This corresponds to the ``target_language_codes`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_configs (Sequence[google.cloud.translate_v3.types.BatchDocumentInputConfig]): + Required. Input configurations. + The total number of files matched should + be <= 100. The total content size to + translate should be <= 100M Unicode + codepoints. The files must use UTF-8 + encoding. + + This corresponds to the ``input_configs`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (google.cloud.translate_v3.types.BatchDocumentOutputConfig): + Required. Output configuration. + If 2 input configs match to the same + file (that is, same input path), we + don't generate output for duplicate + inputs. + + This corresponds to the ``output_config`` 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. @@ -920,12 +982,41 @@ def batch_translate_document( """ # 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, + source_language_code, + target_language_codes, + input_configs, + output_config, + ] + ) + 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 translation_service.BatchTranslateDocumentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, translation_service.BatchTranslateDocumentRequest): request = translation_service.BatchTranslateDocumentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if source_language_code is not None: + request.source_language_code = source_language_code + if target_language_codes is not None: + request.target_language_codes = target_language_codes + if input_configs is not None: + request.input_configs = input_configs + if output_config is not None: + request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/translate_v3beta1/services/translation_service/async_client.py b/google/cloud/translate_v3beta1/services/translation_service/async_client.py index 46f7e2fd..95f27964 100644 --- a/google/cloud/translate_v3beta1/services/translation_service/async_client.py +++ b/google/cloud/translate_v3beta1/services/translation_service/async_client.py @@ -574,6 +574,11 @@ async def batch_translate_document( self, request: translation_service.BatchTranslateDocumentRequest = None, *, + parent: str = None, + source_language_code: str = None, + target_language_codes: Sequence[str] = None, + input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, + output_config: translation_service.BatchDocumentOutputConfig = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -591,6 +596,63 @@ async def batch_translate_document( Args: request (:class:`google.cloud.translate_v3beta1.types.BatchTranslateDocumentRequest`): The request object. The BatchTranslateDocument request. + parent (:class:`str`): + Required. Location to make a regional call. + + Format: + ``projects/{project-number-or-id}/locations/{location-id}``. + + The ``global`` location is not supported for batch + translation. + + Only AutoML Translation models or glossaries within the + same region (have the same location-id) can be used, + otherwise an INVALID_ARGUMENT (400) error is returned. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_language_code (:class:`str`): + Required. The BCP-47 language code of + the input document if known, for + example, "en-US" or "sr-Latn". Supported + language codes are listed in Language + Support + (https://cloud.google.com/translate/docs/languages). + + This corresponds to the ``source_language_code`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + target_language_codes (:class:`Sequence[str]`): + Required. The BCP-47 language code to + use for translation of the input + document. Specify up to 10 language + codes here. + + This corresponds to the ``target_language_codes`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_configs (:class:`Sequence[google.cloud.translate_v3beta1.types.BatchDocumentInputConfig]`): + Required. Input configurations. + The total number of files matched should + be <= 100. The total content size to + translate should be <= 100M Unicode + codepoints. The files must use UTF-8 + encoding. + + This corresponds to the ``input_configs`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (:class:`google.cloud.translate_v3beta1.types.BatchDocumentOutputConfig`): + Required. Output configuration. + If 2 input configs match to the same + file (that is, same input path), we + don't generate output for duplicate + inputs. + + This corresponds to the ``output_config`` 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. @@ -608,8 +670,38 @@ async def batch_translate_document( """ # 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, + source_language_code, + target_language_codes, + input_configs, + output_config, + ] + ) + 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 = translation_service.BatchTranslateDocumentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if source_language_code is not None: + request.source_language_code = source_language_code + if output_config is not None: + request.output_config = output_config + if target_language_codes: + request.target_language_codes.extend(target_language_codes) + if input_configs: + request.input_configs.extend(input_configs) + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( diff --git a/google/cloud/translate_v3beta1/services/translation_service/client.py b/google/cloud/translate_v3beta1/services/translation_service/client.py index fbec4c57..0fc5bb4e 100644 --- a/google/cloud/translate_v3beta1/services/translation_service/client.py +++ b/google/cloud/translate_v3beta1/services/translation_service/client.py @@ -754,6 +754,11 @@ def batch_translate_document( self, request: Union[translation_service.BatchTranslateDocumentRequest, dict] = None, *, + parent: str = None, + source_language_code: str = None, + target_language_codes: Sequence[str] = None, + input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None, + output_config: translation_service.BatchDocumentOutputConfig = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -771,6 +776,63 @@ def batch_translate_document( Args: request (Union[google.cloud.translate_v3beta1.types.BatchTranslateDocumentRequest, dict]): The request object. The BatchTranslateDocument request. + parent (str): + Required. Location to make a regional call. + + Format: + ``projects/{project-number-or-id}/locations/{location-id}``. + + The ``global`` location is not supported for batch + translation. + + Only AutoML Translation models or glossaries within the + same region (have the same location-id) can be used, + otherwise an INVALID_ARGUMENT (400) error is returned. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_language_code (str): + Required. The BCP-47 language code of + the input document if known, for + example, "en-US" or "sr-Latn". Supported + language codes are listed in Language + Support + (https://cloud.google.com/translate/docs/languages). + + This corresponds to the ``source_language_code`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + target_language_codes (Sequence[str]): + Required. The BCP-47 language code to + use for translation of the input + document. Specify up to 10 language + codes here. + + This corresponds to the ``target_language_codes`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_configs (Sequence[google.cloud.translate_v3beta1.types.BatchDocumentInputConfig]): + Required. Input configurations. + The total number of files matched should + be <= 100. The total content size to + translate should be <= 100M Unicode + codepoints. The files must use UTF-8 + encoding. + + This corresponds to the ``input_configs`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (google.cloud.translate_v3beta1.types.BatchDocumentOutputConfig): + Required. Output configuration. + If 2 input configs match to the same + file (that is, same input path), we + don't generate output for duplicate + inputs. + + This corresponds to the ``output_config`` 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. @@ -788,12 +850,41 @@ def batch_translate_document( """ # 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, + source_language_code, + target_language_codes, + input_configs, + output_config, + ] + ) + 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 translation_service.BatchTranslateDocumentRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, translation_service.BatchTranslateDocumentRequest): request = translation_service.BatchTranslateDocumentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if source_language_code is not None: + request.source_language_code = source_language_code + if target_language_codes is not None: + request.target_language_codes = target_language_codes + if input_configs is not None: + request.input_configs = input_configs + if output_config is not None: + request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/tests/unit/gapic/translate_v3/test_translation_service.py b/tests/unit/gapic/translate_v3/test_translation_service.py index 9a733189..8b514890 100644 --- a/tests/unit/gapic/translate_v3/test_translation_service.py +++ b/tests/unit/gapic/translate_v3/test_translation_service.py @@ -1669,6 +1669,168 @@ async def test_batch_translate_document_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] +def test_batch_translate_document_flattened(): + client = TranslationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_translate_document), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_translate_document( + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_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" + assert args[0].source_language_code == "source_language_code_value" + assert args[0].target_language_codes == ["target_language_codes_value"] + assert args[0].input_configs == [ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource(input_uri="input_uri_value") + ) + ] + assert args[0].output_config == translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ) + + +def test_batch_translate_document_flattened_error(): + client = TranslationServiceClient( + 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.batch_translate_document( + translation_service.BatchTranslateDocumentRequest(), + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ), + ) + + +@pytest.mark.asyncio +async def test_batch_translate_document_flattened_async(): + client = TranslationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_translate_document), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_translate_document( + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_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" + assert args[0].source_language_code == "source_language_code_value" + assert args[0].target_language_codes == ["target_language_codes_value"] + assert args[0].input_configs == [ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource(input_uri="input_uri_value") + ) + ] + assert args[0].output_config == translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ) + + +@pytest.mark.asyncio +async def test_batch_translate_document_flattened_error_async(): + client = TranslationServiceAsyncClient( + 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.batch_translate_document( + translation_service.BatchTranslateDocumentRequest(), + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ), + ) + + def test_create_glossary( transport: str = "grpc", request_type=translation_service.CreateGlossaryRequest ): diff --git a/tests/unit/gapic/translate_v3beta1/test_translation_service.py b/tests/unit/gapic/translate_v3beta1/test_translation_service.py index eeed875e..1be623ab 100644 --- a/tests/unit/gapic/translate_v3beta1/test_translation_service.py +++ b/tests/unit/gapic/translate_v3beta1/test_translation_service.py @@ -1551,6 +1551,168 @@ async def test_batch_translate_document_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] +def test_batch_translate_document_flattened(): + client = TranslationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_translate_document), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_translate_document( + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_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" + assert args[0].source_language_code == "source_language_code_value" + assert args[0].target_language_codes == ["target_language_codes_value"] + assert args[0].input_configs == [ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource(input_uri="input_uri_value") + ) + ] + assert args[0].output_config == translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ) + + +def test_batch_translate_document_flattened_error(): + client = TranslationServiceClient( + 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.batch_translate_document( + translation_service.BatchTranslateDocumentRequest(), + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ), + ) + + +@pytest.mark.asyncio +async def test_batch_translate_document_flattened_async(): + client = TranslationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_translate_document), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_translate_document( + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_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" + assert args[0].source_language_code == "source_language_code_value" + assert args[0].target_language_codes == ["target_language_codes_value"] + assert args[0].input_configs == [ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource(input_uri="input_uri_value") + ) + ] + assert args[0].output_config == translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ) + + +@pytest.mark.asyncio +async def test_batch_translate_document_flattened_error_async(): + client = TranslationServiceAsyncClient( + 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.batch_translate_document( + translation_service.BatchTranslateDocumentRequest(), + parent="parent_value", + source_language_code="source_language_code_value", + target_language_codes=["target_language_codes_value"], + input_configs=[ + translation_service.BatchDocumentInputConfig( + gcs_source=translation_service.GcsSource( + input_uri="input_uri_value" + ) + ) + ], + output_config=translation_service.BatchDocumentOutputConfig( + gcs_destination=translation_service.GcsDestination( + output_uri_prefix="output_uri_prefix_value" + ) + ), + ) + + def test_create_glossary( transport: str = "grpc", request_type=translation_service.CreateGlossaryRequest ):