Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

from google.cloud import scheduler_v1beta1
Expand Down Expand Up @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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 = {}
Expand All @@ -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 = {}
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand Down