def test_get_cluster(self): # Setup Expected Response project_id_2 = 'projectId2939242356' cluster_name_2 = 'clusterName2875867491' cluster_uuid = 'clusterUuid-1017854240' expected_response = { 'project_id': project_id_2, 'cluster_name': cluster_name_2, 'cluster_uuid': cluster_uuid } expected_response = clusters_pb2.Cluster(**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 = dataproc_v1.ClusterControllerClient() # Setup Request project_id = 'projectId-1969970175' region = 'region-934795532' cluster_name = 'clusterName-1018081872' response = client.get_cluster(project_id, region, cluster_name) assert expected_response == response assert len(channel.requests) == 1 expected_request = clusters_pb2.GetClusterRequest( project_id=project_id, region=region, cluster_name=cluster_name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_cluster(self): # Setup Expected Response project_id_2 = 'projectId2939242356' cluster_name = 'clusterName-1018081872' cluster_uuid = 'clusterUuid-1017854240' expected_response = { 'project_id': project_id_2, 'cluster_name': cluster_name, 'cluster_uuid': cluster_uuid } expected_response = clusters_pb2.Cluster(**expected_response) operation = operations_pb2.Operation( name='operations/test_create_cluster', done=True) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) client = dataproc_v1.ClusterControllerClient(channel=channel) # Setup Request project_id = 'projectId-1969970175' region = 'region-934795532' cluster = {} response = client.create_cluster(project_id, region, cluster) result = response.result() assert expected_response == result assert len(channel.requests) == 1 expected_request = clusters_pb2.CreateClusterRequest( project_id=project_id, region=region, cluster=cluster) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_update_cluster(self): # Setup Expected Response project_id_2 = "projectId2939242356" cluster_name_2 = "clusterName2875867491" cluster_uuid = "clusterUuid-1017854240" expected_response = { "project_id": project_id_2, "cluster_name": cluster_name_2, "cluster_uuid": cluster_uuid, } expected_response = clusters_pb2.Cluster(**expected_response) operation = operations_pb2.Operation( name="operations/test_update_cluster", done=True ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dataproc_v1.ClusterControllerClient() # Setup Request project_id = "projectId-1969970175" region = "region-934795532" cluster_name = "clusterName-1018081872" cluster = {} update_mask = {} response = client.update_cluster( project_id, region, cluster_name, cluster, update_mask ) result = response.result() assert expected_response == result assert len(channel.requests) == 1 expected_request = clusters_pb2.UpdateClusterRequest( project_id=project_id, region=region, cluster_name=cluster_name, cluster=cluster, update_mask=update_mask, ) actual_request = channel.requests[0][1] assert expected_request == actual_request