diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index 803b98a27264..2442802b00a3 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -103,7 +103,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index 433557c2e420..2907c6c759fa 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -104,7 +104,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index 2f7a71432d74..775dce996360 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -104,7 +104,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py index b31c4c99ea87..a4e384ed7e2c 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -277,20 +277,20 @@ def test_document_processor_service_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -359,7 +359,7 @@ def test_document_processor_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -458,7 +458,7 @@ def test_document_processor_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -493,7 +493,7 @@ def test_document_processor_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -526,9 +526,10 @@ def test_document_processor_service_client_client_options_from_dict(): ) -def test_process_document( - transport: str = "grpc", request_type=document_processor_service.ProcessRequest -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.ProcessRequest, dict,] +) +def test_process_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -552,10 +553,6 @@ def test_process_document( assert isinstance(response, document_processor_service.ProcessResponse) -def test_process_document_from_dict(): - test_process_document(request_type=dict) - - def test_process_document_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. @@ -737,9 +734,10 @@ async def test_process_document_flattened_error_async(): ) -def test_batch_process_documents( - transport: str = "grpc", request_type=document_processor_service.BatchProcessRequest -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.BatchProcessRequest, dict,] +) +def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -765,10 +763,6 @@ def test_batch_process_documents( assert isinstance(response, future.Future) -def test_batch_process_documents_from_dict(): - test_batch_process_documents(request_type=dict) - - def test_batch_process_documents_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. @@ -962,10 +956,10 @@ async def test_batch_process_documents_flattened_error_async(): ) -def test_review_document( - transport: str = "grpc", - request_type=document_processor_service.ReviewDocumentRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.ReviewDocumentRequest, dict,] +) +def test_review_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -989,10 +983,6 @@ def test_review_document( assert isinstance(response, future.Future) -def test_review_document_from_dict(): - test_review_document(request_type=dict) - - def test_review_document_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. @@ -1765,7 +1755,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index b0afb0d38707..4d9c59ec5dbb 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -271,20 +271,20 @@ def test_document_understanding_service_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -353,7 +353,7 @@ def test_document_understanding_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -452,7 +452,7 @@ def test_document_understanding_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -487,7 +487,7 @@ def test_document_understanding_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -520,10 +520,10 @@ def test_document_understanding_service_client_client_options_from_dict(): ) -def test_batch_process_documents( - transport: str = "grpc", - request_type=document_understanding.BatchProcessDocumentsRequest, -): +@pytest.mark.parametrize( + "request_type", [document_understanding.BatchProcessDocumentsRequest, dict,] +) +def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentUnderstandingServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -549,10 +549,6 @@ def test_batch_process_documents( assert isinstance(response, future.Future) -def test_batch_process_documents_from_dict(): - test_batch_process_documents(request_type=dict) - - def test_batch_process_documents_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. @@ -764,9 +760,10 @@ async def test_batch_process_documents_flattened_error_async(): ) -def test_process_document( - transport: str = "grpc", request_type=document_understanding.ProcessDocumentRequest -): +@pytest.mark.parametrize( + "request_type", [document_understanding.ProcessDocumentRequest, dict,] +) +def test_process_document(request_type, transport: str = "grpc"): client = DocumentUnderstandingServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -794,10 +791,6 @@ def test_process_document( assert response.text == "text_value" -def test_process_document_from_dict(): - test_process_document(request_type=dict) - - def test_process_document_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. @@ -1440,7 +1433,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 4fa6fd6a8fac..2bac0ae97d06 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -283,20 +283,20 @@ def test_document_processor_service_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -365,7 +365,7 @@ def test_document_processor_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -464,7 +464,7 @@ def test_document_processor_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -499,7 +499,7 @@ def test_document_processor_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -532,9 +532,10 @@ def test_document_processor_service_client_client_options_from_dict(): ) -def test_process_document( - transport: str = "grpc", request_type=document_processor_service.ProcessRequest -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.ProcessRequest, dict,] +) +def test_process_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -561,10 +562,6 @@ def test_process_document( assert response.human_review_operation == "human_review_operation_value" -def test_process_document_from_dict(): - test_process_document(request_type=dict) - - def test_process_document_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. @@ -749,9 +746,10 @@ async def test_process_document_flattened_error_async(): ) -def test_batch_process_documents( - transport: str = "grpc", request_type=document_processor_service.BatchProcessRequest -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.BatchProcessRequest, dict,] +) +def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -777,10 +775,6 @@ def test_batch_process_documents( assert isinstance(response, future.Future) -def test_batch_process_documents_from_dict(): - test_batch_process_documents(request_type=dict) - - def test_batch_process_documents_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. @@ -974,10 +968,10 @@ async def test_batch_process_documents_flattened_error_async(): ) -def test_fetch_processor_types( - transport: str = "grpc", - request_type=document_processor_service.FetchProcessorTypesRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.FetchProcessorTypesRequest, dict,] +) +def test_fetch_processor_types(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1003,10 +997,6 @@ def test_fetch_processor_types( assert isinstance(response, document_processor_service.FetchProcessorTypesResponse) -def test_fetch_processor_types_from_dict(): - test_fetch_processor_types(request_type=dict) - - def test_fetch_processor_types_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. @@ -1202,10 +1192,10 @@ async def test_fetch_processor_types_flattened_error_async(): ) -def test_list_processors( - transport: str = "grpc", - request_type=document_processor_service.ListProcessorsRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.ListProcessorsRequest, dict,] +) +def test_list_processors(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1232,10 +1222,6 @@ def test_list_processors( assert response.next_page_token == "next_page_token_value" -def test_list_processors_from_dict(): - test_list_processors(request_type=dict) - - def test_list_processors_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. @@ -1420,9 +1406,9 @@ async def test_list_processors_flattened_error_async(): ) -def test_list_processors_pager(): +def test_list_processors_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1462,9 +1448,9 @@ def test_list_processors_pager(): assert all(isinstance(i, processor.Processor) for i in results) -def test_list_processors_pages(): +def test_list_processors_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1574,10 +1560,10 @@ async def test_list_processors_async_pages(): assert page_.raw_page.next_page_token == token -def test_create_processor( - transport: str = "grpc", - request_type=document_processor_service.CreateProcessorRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.CreateProcessorRequest, dict,] +) +def test_create_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1616,10 +1602,6 @@ def test_create_processor( assert response.kms_key_name == "kms_key_name_value" -def test_create_processor_from_dict(): - test_create_processor(request_type=dict) - - def test_create_processor_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. @@ -1830,10 +1812,10 @@ async def test_create_processor_flattened_error_async(): ) -def test_delete_processor( - transport: str = "grpc", - request_type=document_processor_service.DeleteProcessorRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.DeleteProcessorRequest, dict,] +) +def test_delete_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1857,10 +1839,6 @@ def test_delete_processor( assert isinstance(response, future.Future) -def test_delete_processor_from_dict(): - test_delete_processor(request_type=dict) - - def test_delete_processor_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. @@ -2042,10 +2020,10 @@ async def test_delete_processor_flattened_error_async(): ) -def test_enable_processor( - transport: str = "grpc", - request_type=document_processor_service.EnableProcessorRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.EnableProcessorRequest, dict,] +) +def test_enable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2069,10 +2047,6 @@ def test_enable_processor( assert isinstance(response, future.Future) -def test_enable_processor_from_dict(): - test_enable_processor(request_type=dict) - - def test_enable_processor_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. @@ -2178,10 +2152,10 @@ async def test_enable_processor_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_disable_processor( - transport: str = "grpc", - request_type=document_processor_service.DisableProcessorRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.DisableProcessorRequest, dict,] +) +def test_disable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2207,10 +2181,6 @@ def test_disable_processor( assert isinstance(response, future.Future) -def test_disable_processor_from_dict(): - test_disable_processor(request_type=dict) - - def test_disable_processor_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. @@ -2324,10 +2294,10 @@ async def test_disable_processor_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_review_document( - transport: str = "grpc", - request_type=document_processor_service.ReviewDocumentRequest, -): +@pytest.mark.parametrize( + "request_type", [document_processor_service.ReviewDocumentRequest, dict,] +) +def test_review_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2351,10 +2321,6 @@ def test_review_document( assert isinstance(response, future.Future) -def test_review_document_from_dict(): - test_review_document(request_type=dict) - - def test_review_document_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. @@ -3159,7 +3125,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object(