diff --git a/scheduler/google/cloud/scheduler_v1beta1/gapic/cloud_scheduler_client.py b/scheduler/google/cloud/scheduler_v1beta1/gapic/cloud_scheduler_client.py index 4c43cede8dd3..dfe34ce5d465 100644 --- a/scheduler/google/cloud/scheduler_v1beta1/gapic/cloud_scheduler_client.py +++ b/scheduler/google/cloud/scheduler_v1beta1/gapic/cloud_scheduler_client.py @@ -106,7 +106,7 @@ def __init__(self, transport=None, channel=None, credentials=None, - client_config=cloud_scheduler_client_config.config, + client_config=None, client_info=None): """Constructor. @@ -139,13 +139,20 @@ def __init__(self, your own client library. """ # Raise deprecation warnings for things we want to go away. - if client_config: - warnings.warn('The `client_config` argument is deprecated.', - PendingDeprecationWarning) + if client_config is not None: + warnings.warn( + 'The `client_config` argument is deprecated.', + PendingDeprecationWarning, + stacklevel=2) + else: + client_config = cloud_scheduler_client_config.config + if channel: warnings.warn( 'The `channel` argument is deprecated; use ' - '`transport` instead.', PendingDeprecationWarning) + '`transport` instead.', + PendingDeprecationWarning, + stacklevel=2) # Instantiate the transport. # The transport is responsible for handling serialization and diff --git a/scheduler/google/cloud/scheduler_v1beta1/gapic/transports/cloud_scheduler_grpc_transport.py b/scheduler/google/cloud/scheduler_v1beta1/gapic/transports/cloud_scheduler_grpc_transport.py index 86c676cb6ff4..7a974dd343b2 100644 --- a/scheduler/google/cloud/scheduler_v1beta1/gapic/transports/cloud_scheduler_grpc_transport.py +++ b/scheduler/google/cloud/scheduler_v1beta1/gapic/transports/cloud_scheduler_grpc_transport.py @@ -62,6 +62,8 @@ def __init__(self, credentials=credentials, ) + self._channel = channel + # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. self._stubs = { @@ -92,6 +94,15 @@ def create_channel(cls, scopes=cls._OAUTH_SCOPES, ) + @property + def channel(self): + """The gRPC channel used by the transport. + + Returns: + grpc.Channel: A gRPC channel object. + """ + return self._channel + @property def list_jobs(self): """Return the gRPC stub for {$apiMethod.name}. diff --git a/scheduler/tests/unit/gapic/v1beta1/test_cloud_scheduler_client_v1beta1.py b/scheduler/tests/unit/gapic/v1beta1/test_cloud_scheduler_client_v1beta1.py index e8fb68631d50..5f7a62a024f9 100644 --- a/scheduler/tests/unit/gapic/v1beta1/test_cloud_scheduler_client_v1beta1.py +++ b/scheduler/tests/unit/gapic/v1beta1/test_cloud_scheduler_client_v1beta1.py @@ -15,6 +15,7 @@ # limitations under the License. """Unit tests.""" +import mock import pytest from google.cloud import scheduler_v1beta1 @@ -74,7 +75,10 @@ def test_list_jobs(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -92,7 +96,10 @@ def test_list_jobs(self): def test_list_jobs_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -117,7 +124,10 @@ def test_get_job(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -133,7 +143,10 @@ def test_get_job(self): def test_get_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -157,7 +170,10 @@ def test_create_job(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -175,7 +191,10 @@ def test_create_job(self): def test_create_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -200,7 +219,10 @@ def test_update_job(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request job = {} @@ -216,7 +238,10 @@ def test_update_job(self): def test_update_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request job = {} @@ -226,7 +251,10 @@ def test_update_job_exception(self): def test_delete_job(self): channel = ChannelStub() - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -241,7 +269,10 @@ def test_delete_job(self): def test_delete_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -265,7 +296,10 @@ def test_pause_job(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -281,7 +315,10 @@ def test_pause_job(self): def test_pause_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -305,7 +342,10 @@ def test_resume_job(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -321,7 +361,10 @@ def test_resume_job(self): def test_resume_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -345,7 +388,10 @@ def test_run_job(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup Request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]') @@ -361,7 +407,10 @@ def test_run_job(self): def test_run_job_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = scheduler_v1beta1.CloudSchedulerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = scheduler_v1beta1.CloudSchedulerClient() # Setup request name = client.job_path('[PROJECT]', '[LOCATION]', '[JOB]')