def test_list_clusters(self): # Setup Expected Response next_page_token = "" clusters_element = {} clusters = [clusters_element] expected_response = {"next_page_token": next_page_token, "clusters": clusters} expected_response = clusters_pb2.ListClustersResponse(**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_v1beta2.ClusterControllerClient() # Setup Request project_id = "projectId-1969970175" region = "region-934795532" paged_list_response = client.list_clusters(project_id, region) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.clusters[0] == resources[0] assert len(channel.requests) == 1 expected_request = clusters_pb2.ListClustersRequest( project_id=project_id, region=region ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_clusters(self): # Setup Expected Response next_page_token = '' clusters_element = {} clusters = [clusters_element] expected_response = { 'next_page_token': next_page_token, 'clusters': clusters } expected_response = clusters_pb2.ListClustersResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dataproc_v1beta2.ClusterControllerClient(channel=channel) # Setup Request project_id = 'projectId-1969970175' region = 'region-934795532' paged_list_response = client.list_clusters(project_id, region) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.clusters[0] == resources[0] assert len(channel.requests) == 1 expected_request = clusters_pb2.ListClustersRequest( project_id=project_id, region=region) actual_request = channel.requests[0][1] assert expected_request == actual_request