diff --git a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/base.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/base.py index ac7d4af95e01..9374c179ddb4 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/base.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1/services/cloud_scheduler/transports/base.py @@ -102,7 +102,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-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/base.py b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/base.py index 02aa59c00819..7f6d60d66bbb 100644 --- a/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/base.py +++ b/packages/google-cloud-scheduler/google/cloud/scheduler_v1beta1/services/cloud_scheduler/transports/base.py @@ -102,7 +102,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-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py index 7cd4acb5534c..05f2b818d019 100644 --- a/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py +++ b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1/test_cloud_scheduler.py @@ -254,20 +254,20 @@ def test_cloud_scheduler_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, @@ -326,7 +326,7 @@ def test_cloud_scheduler_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 @@ -421,7 +421,7 @@ def test_cloud_scheduler_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, @@ -452,7 +452,7 @@ def test_cloud_scheduler_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", @@ -485,9 +485,8 @@ def test_cloud_scheduler_client_client_options_from_dict(): ) -def test_list_jobs( - transport: str = "grpc", request_type=cloudscheduler.ListJobsRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.ListJobsRequest, dict,]) +def test_list_jobs(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -514,10 +513,6 @@ def test_list_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_jobs_from_dict(): - test_list_jobs(request_type=dict) - - def test_list_jobs_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. @@ -693,8 +688,10 @@ async def test_list_jobs_flattened_error_async(): ) -def test_list_jobs_pager(): - client = CloudSchedulerClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_jobs_pager(transport_name: str = "grpc"): + client = CloudSchedulerClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_jobs), "__call__") as call: @@ -722,8 +719,10 @@ def test_list_jobs_pager(): assert all(isinstance(i, job.Job) for i in results) -def test_list_jobs_pages(): - client = CloudSchedulerClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_jobs_pages(transport_name: str = "grpc"): + client = CloudSchedulerClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_jobs), "__call__") as call: @@ -795,7 +794,8 @@ async def test_list_jobs_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_job(transport: str = "grpc", request_type=cloudscheduler.GetJobRequest): +@pytest.mark.parametrize("request_type", [cloudscheduler.GetJobRequest, dict,]) +def test_get_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -831,10 +831,6 @@ def test_get_job(transport: str = "grpc", request_type=cloudscheduler.GetJobRequ assert response.state == job.Job.State.ENABLED -def test_get_job_from_dict(): - test_get_job(request_type=dict) - - def test_get_job_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. @@ -1016,9 +1012,8 @@ async def test_get_job_flattened_error_async(): ) -def test_create_job( - transport: str = "grpc", request_type=cloudscheduler.CreateJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.CreateJobRequest, dict,]) +def test_create_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1054,10 +1049,6 @@ def test_create_job( assert response.state == gcs_job.Job.State.ENABLED -def test_create_job_from_dict(): - test_create_job(request_type=dict) - - def test_create_job_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. @@ -1253,9 +1244,8 @@ async def test_create_job_flattened_error_async(): ) -def test_update_job( - transport: str = "grpc", request_type=cloudscheduler.UpdateJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.UpdateJobRequest, dict,]) +def test_update_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1291,10 +1281,6 @@ def test_update_job( assert response.state == gcs_job.Job.State.ENABLED -def test_update_job_from_dict(): - test_update_job(request_type=dict) - - def test_update_job_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. @@ -1492,9 +1478,8 @@ async def test_update_job_flattened_error_async(): ) -def test_delete_job( - transport: str = "grpc", request_type=cloudscheduler.DeleteJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.DeleteJobRequest, dict,]) +def test_delete_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1518,10 +1503,6 @@ def test_delete_job( assert response is None -def test_delete_job_from_dict(): - test_delete_job(request_type=dict) - - def test_delete_job_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. @@ -1690,9 +1671,8 @@ async def test_delete_job_flattened_error_async(): ) -def test_pause_job( - transport: str = "grpc", request_type=cloudscheduler.PauseJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.PauseJobRequest, dict,]) +def test_pause_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1728,10 +1708,6 @@ def test_pause_job( assert response.state == job.Job.State.ENABLED -def test_pause_job_from_dict(): - test_pause_job(request_type=dict) - - def test_pause_job_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. @@ -1913,9 +1889,8 @@ async def test_pause_job_flattened_error_async(): ) -def test_resume_job( - transport: str = "grpc", request_type=cloudscheduler.ResumeJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.ResumeJobRequest, dict,]) +def test_resume_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1951,10 +1926,6 @@ def test_resume_job( assert response.state == job.Job.State.ENABLED -def test_resume_job_from_dict(): - test_resume_job(request_type=dict) - - def test_resume_job_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. @@ -2136,7 +2107,8 @@ async def test_resume_job_flattened_error_async(): ) -def test_run_job(transport: str = "grpc", request_type=cloudscheduler.RunJobRequest): +@pytest.mark.parametrize("request_type", [cloudscheduler.RunJobRequest, dict,]) +def test_run_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2172,10 +2144,6 @@ def test_run_job(transport: str = "grpc", request_type=cloudscheduler.RunJobRequ assert response.state == job.Job.State.ENABLED -def test_run_job_from_dict(): - test_run_job(request_type=dict) - - def test_run_job_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. @@ -2898,7 +2866,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-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py index 091ca064580e..826c7e74104e 100644 --- a/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py +++ b/packages/google-cloud-scheduler/tests/unit/gapic/scheduler_v1beta1/test_cloud_scheduler.py @@ -256,20 +256,20 @@ def test_cloud_scheduler_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, @@ -328,7 +328,7 @@ def test_cloud_scheduler_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 @@ -423,7 +423,7 @@ def test_cloud_scheduler_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, @@ -454,7 +454,7 @@ def test_cloud_scheduler_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", @@ -487,9 +487,8 @@ def test_cloud_scheduler_client_client_options_from_dict(): ) -def test_list_jobs( - transport: str = "grpc", request_type=cloudscheduler.ListJobsRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.ListJobsRequest, dict,]) +def test_list_jobs(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -516,10 +515,6 @@ def test_list_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_jobs_from_dict(): - test_list_jobs(request_type=dict) - - def test_list_jobs_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. @@ -695,8 +690,10 @@ async def test_list_jobs_flattened_error_async(): ) -def test_list_jobs_pager(): - client = CloudSchedulerClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_jobs_pager(transport_name: str = "grpc"): + client = CloudSchedulerClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_jobs), "__call__") as call: @@ -724,8 +721,10 @@ def test_list_jobs_pager(): assert all(isinstance(i, job.Job) for i in results) -def test_list_jobs_pages(): - client = CloudSchedulerClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_jobs_pages(transport_name: str = "grpc"): + client = CloudSchedulerClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_jobs), "__call__") as call: @@ -797,7 +796,8 @@ async def test_list_jobs_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_job(transport: str = "grpc", request_type=cloudscheduler.GetJobRequest): +@pytest.mark.parametrize("request_type", [cloudscheduler.GetJobRequest, dict,]) +def test_get_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -833,10 +833,6 @@ def test_get_job(transport: str = "grpc", request_type=cloudscheduler.GetJobRequ assert response.state == job.Job.State.ENABLED -def test_get_job_from_dict(): - test_get_job(request_type=dict) - - def test_get_job_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. @@ -1018,9 +1014,8 @@ async def test_get_job_flattened_error_async(): ) -def test_create_job( - transport: str = "grpc", request_type=cloudscheduler.CreateJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.CreateJobRequest, dict,]) +def test_create_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1056,10 +1051,6 @@ def test_create_job( assert response.state == gcs_job.Job.State.ENABLED -def test_create_job_from_dict(): - test_create_job(request_type=dict) - - def test_create_job_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. @@ -1255,9 +1246,8 @@ async def test_create_job_flattened_error_async(): ) -def test_update_job( - transport: str = "grpc", request_type=cloudscheduler.UpdateJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.UpdateJobRequest, dict,]) +def test_update_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1293,10 +1283,6 @@ def test_update_job( assert response.state == gcs_job.Job.State.ENABLED -def test_update_job_from_dict(): - test_update_job(request_type=dict) - - def test_update_job_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. @@ -1494,9 +1480,8 @@ async def test_update_job_flattened_error_async(): ) -def test_delete_job( - transport: str = "grpc", request_type=cloudscheduler.DeleteJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.DeleteJobRequest, dict,]) +def test_delete_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1520,10 +1505,6 @@ def test_delete_job( assert response is None -def test_delete_job_from_dict(): - test_delete_job(request_type=dict) - - def test_delete_job_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. @@ -1692,9 +1673,8 @@ async def test_delete_job_flattened_error_async(): ) -def test_pause_job( - transport: str = "grpc", request_type=cloudscheduler.PauseJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.PauseJobRequest, dict,]) +def test_pause_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1730,10 +1710,6 @@ def test_pause_job( assert response.state == job.Job.State.ENABLED -def test_pause_job_from_dict(): - test_pause_job(request_type=dict) - - def test_pause_job_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. @@ -1915,9 +1891,8 @@ async def test_pause_job_flattened_error_async(): ) -def test_resume_job( - transport: str = "grpc", request_type=cloudscheduler.ResumeJobRequest -): +@pytest.mark.parametrize("request_type", [cloudscheduler.ResumeJobRequest, dict,]) +def test_resume_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1953,10 +1928,6 @@ def test_resume_job( assert response.state == job.Job.State.ENABLED -def test_resume_job_from_dict(): - test_resume_job(request_type=dict) - - def test_resume_job_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. @@ -2138,7 +2109,8 @@ async def test_resume_job_flattened_error_async(): ) -def test_run_job(transport: str = "grpc", request_type=cloudscheduler.RunJobRequest): +@pytest.mark.parametrize("request_type", [cloudscheduler.RunJobRequest, dict,]) +def test_run_job(request_type, transport: str = "grpc"): client = CloudSchedulerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2174,10 +2146,6 @@ def test_run_job(transport: str = "grpc", request_type=cloudscheduler.RunJobRequ assert response.state == job.Job.State.ENABLED -def test_run_job_from_dict(): - test_run_job(request_type=dict) - - def test_run_job_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. @@ -2900,7 +2868,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(