diff --git a/iot/google/cloud/iot_v1/gapic/device_manager_client.py b/iot/google/cloud/iot_v1/gapic/device_manager_client.py index 0331ed1a4118..2753f75a8d83 100644 --- a/iot/google/cloud/iot_v1/gapic/device_manager_client.py +++ b/iot/google/cloud/iot_v1/gapic/device_manager_client.py @@ -112,7 +112,7 @@ def __init__(self, transport=None, channel=None, credentials=None, - client_config=device_manager_client_config.config, + client_config=None, client_info=None): """Constructor. @@ -145,13 +145,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 = device_manager_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/iot/google/cloud/iot_v1/gapic/transports/device_manager_grpc_transport.py b/iot/google/cloud/iot_v1/gapic/transports/device_manager_grpc_transport.py index 69513fe2a82d..d90a41405c08 100644 --- a/iot/google/cloud/iot_v1/gapic/transports/device_manager_grpc_transport.py +++ b/iot/google/cloud/iot_v1/gapic/transports/device_manager_grpc_transport.py @@ -65,6 +65,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 = { @@ -95,6 +97,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 create_device_registry(self): """Return the gRPC stub for {$apiMethod.name}. diff --git a/iot/synth.py b/iot/synth.py index e8700e749720..a29841920a22 100644 --- a/iot/synth.py +++ b/iot/synth.py @@ -29,3 +29,5 @@ artman_output_name='iot-v1') s.move(library / 'google/cloud/iot_v1') +s.move(library / 'tests/unit/gapic') +s.move(library / 'tests/system/gapic') diff --git a/iot/tests/system/gapic/v1/test_system_device_manager_v1.py b/iot/tests/system/gapic/v1/test_system_device_manager_v1.py index c42e12536473..911426bf4079 100644 --- a/iot/tests/system/gapic/v1/test_system_device_manager_v1.py +++ b/iot/tests/system/gapic/v1/test_system_device_manager_v1.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/iot/tests/unit/gapic/v1/test_device_manager_client_v1.py b/iot/tests/unit/gapic/v1/test_device_manager_client_v1.py index b632e5cec3a3..d4f1b0ce83ec 100644 --- a/iot/tests/unit/gapic/v1/test_device_manager_client_v1.py +++ b/iot/tests/unit/gapic/v1/test_device_manager_client_v1.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +15,7 @@ # limitations under the License. """Unit tests.""" +import mock import pytest from google.cloud import iot_v1 @@ -73,7 +76,10 @@ def test_create_device_registry(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -91,7 +97,10 @@ def test_create_device_registry(self): def test_create_device_registry_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -109,7 +118,10 @@ def test_get_device_registry(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request name = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -126,7 +138,10 @@ def test_get_device_registry(self): def test_get_device_registry_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request name = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -143,7 +158,10 @@ def test_update_device_registry(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request device_registry = {} @@ -161,7 +179,10 @@ def test_update_device_registry(self): def test_update_device_registry_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request device_registry = {} @@ -172,7 +193,10 @@ def test_update_device_registry_exception(self): def test_delete_device_registry(self): channel = ChannelStub() - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request name = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -188,7 +212,10 @@ def test_delete_device_registry(self): def test_delete_device_registry_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request name = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -210,7 +237,10 @@ def test_list_device_registries(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -229,7 +259,10 @@ def test_list_device_registries(self): def test_list_device_registries_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request parent = client.location_path('[PROJECT]', '[LOCATION]') @@ -254,7 +287,10 @@ def test_create_device(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request parent = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -272,7 +308,10 @@ def test_create_device(self): def test_create_device_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request parent = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -297,7 +336,10 @@ def test_get_device(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -314,7 +356,10 @@ def test_get_device(self): def test_get_device_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -339,7 +384,10 @@ def test_update_device(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request device = {} @@ -357,7 +405,10 @@ def test_update_device(self): def test_update_device_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request device = {} @@ -368,7 +419,10 @@ def test_update_device_exception(self): def test_delete_device(self): channel = ChannelStub() - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -384,7 +438,10 @@ def test_delete_device(self): def test_delete_device_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -407,7 +464,10 @@ def test_list_devices(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request parent = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -425,7 +485,10 @@ def test_list_devices(self): def test_list_devices_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request parent = client.registry_path('[PROJECT]', '[LOCATION]', '[REGISTRY]') @@ -443,7 +506,10 @@ def test_modify_cloud_to_device_config(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -462,7 +528,10 @@ def test_modify_cloud_to_device_config(self): def test_modify_cloud_to_device_config_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -480,7 +549,10 @@ def test_list_device_config_versions(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -498,7 +570,10 @@ def test_list_device_config_versions(self): def test_list_device_config_versions_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -515,7 +590,10 @@ def test_list_device_states(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -533,7 +611,10 @@ def test_list_device_states(self): def test_list_device_states_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request name = client.device_path('[PROJECT]', '[LOCATION]', '[REGISTRY]', @@ -551,7 +632,10 @@ def test_set_iam_policy(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request resource = client.registry_path('[PROJECT]', '[LOCATION]', @@ -570,7 +654,10 @@ def test_set_iam_policy(self): def test_set_iam_policy_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request resource = client.registry_path('[PROJECT]', '[LOCATION]', @@ -589,7 +676,10 @@ def test_get_iam_policy(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request resource = client.registry_path('[PROJECT]', '[LOCATION]', @@ -607,7 +697,10 @@ def test_get_iam_policy(self): def test_get_iam_policy_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request resource = client.registry_path('[PROJECT]', '[LOCATION]', @@ -624,7 +717,10 @@ def test_test_iam_permissions(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup Request resource = client.registry_path('[PROJECT]', '[LOCATION]', @@ -643,7 +739,10 @@ def test_test_iam_permissions(self): def test_test_iam_permissions_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = iot_v1.DeviceManagerClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = iot_v1.DeviceManagerClient() # Setup request resource = client.registry_path('[PROJECT]', '[LOCATION]',