def test_update_device(self): # Setup Expected Response id_ = 'id3355' name = 'name3373707' num_id = 1034366860 blocked = True expected_response = { 'id': id_, 'name': name, 'num_id': num_id, 'blocked': blocked } expected_response = resources_pb2.Device(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) 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 = {} update_mask = {} response = client.update_device(device, update_mask) assert expected_response == response assert len(channel.requests) == 1 expected_request = device_manager_pb2.UpdateDeviceRequest( device=device, update_mask=update_mask) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_device(self): # Setup Expected Response id_ = 'id3355' name_2 = 'name2-1052831874' num_id = 1034366860 blocked = True expected_response = { 'id': id_, 'name': name_2, 'num_id': num_id, 'blocked': blocked } expected_response = resources_pb2.Device(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) 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]', '[DEVICE]') response = client.get_device(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = device_manager_pb2.GetDeviceRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_device(self): # Setup Expected Response id_ = "id3355" name_2 = "name2-1052831874" num_id = 1034366860 blocked = True expected_response = { "id": id_, "name": name_2, "num_id": num_id, "blocked": blocked, } expected_response = resources_pb2.Device(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) 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]", "[DEVICE]") response = client.get_device(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = device_manager_pb2.GetDeviceRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_device(self): # Setup Expected Response id_ = 'id3355' name = 'name3373707' num_id = 1034366860 blocked = True expected_response = { 'id': id_, 'name': name, 'num_id': num_id, 'blocked': blocked } expected_response = resources_pb2.Device(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) 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]') device = {} response = client.create_device(parent, device) assert expected_response == response assert len(channel.requests) == 1 expected_request = device_manager_pb2.CreateDeviceRequest( parent=parent, device=device) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_update_device(self): # Setup Expected Response id_ = 'id3355' name = 'name3373707' num_id = 1034366860 blocked = True expected_response = { 'id': id_, 'name': name, 'num_id': num_id, 'blocked': blocked } expected_response = resources_pb2.Device(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = iot_v1.DeviceManagerClient(channel=channel) # Setup Request device = {} update_mask = {} response = client.update_device(device, update_mask) assert expected_response == response assert len(channel.requests) == 1 expected_request = device_manager_pb2.UpdateDeviceRequest( device=device, update_mask=update_mask) actual_request = channel.requests[0][1] assert expected_request == actual_request