-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cluster - Client library API migration changes #177
base: main
Are you sure you want to change the base?
Changes from 6 commits
14a7916
75e1576
c8f9643
654b621
9659c02
3708794
25e25c1
cdec0d7
2a37f2c
d539d90
1d60038
611fbac
cd84677
2b7b95b
9b71492
312902a
68c21db
4d70971
65d004f
2eb3d98
cb818d0
8a6072a
c5ae698
6daa124
7f64795
50f2d2d
a734f1e
ff65fda
7580728
36dfd9e
a3edf3d
d8e3567
f87ce93
f656955
218ecde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,29 +13,54 @@ | |
# limitations under the License. | ||
|
||
import json | ||
from unittest import mock | ||
|
||
from dataproc_jupyter_plugin.tests import mocks | ||
|
||
from google.cloud.dataproc_v1.services.cluster_controller import ( | ||
ClusterControllerClient, | ||
pagers | ||
) | ||
from google.auth import credentials as ga_credentials | ||
from google.cloud.dataproc_v1.types import clusters | ||
import pytest | ||
|
||
async def test_list_clusters(monkeypatch, jp_fetch): | ||
mocks.patch_mocks(monkeypatch) | ||
|
||
mock_project_id = "credentials-project" | ||
mock_page_token = "mock-page-token" | ||
mock_region_id = "mock-region" | ||
mock_page_size = "mock_page_size" | ||
response = await jp_fetch( | ||
"dataproc-plugin", | ||
"clusterList", | ||
params={"pageSize": mock_page_size, "pageToken": mock_page_token}, | ||
) | ||
assert response.code == 200 | ||
payload = json.loads(response.body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still need to parse and validate the response body, which means we should also be mocking the list clusters call within the Dataproc client library. |
||
assert ( | ||
payload["api_endpoint"] | ||
== f"https://dataproc.googleapis.com//v1/projects/credentials-project/regions/{mock_region_id}/clusters?pageSize={mock_page_size}&pageToken={mock_page_token}" | ||
@pytest.mark.parametrize( | ||
"request_type", | ||
[ | ||
clusters.ListClustersRequest, | ||
dict, | ||
], | ||
) | ||
|
||
def test_list_clusters(request_type, transport: str = "grpc"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This modified method does not actually test listing clusters via the server. There needs to be an invocation of the |
||
client = ClusterControllerClient( | ||
credentials=ga_credentials.AnonymousCredentials(), | ||
transport=transport, | ||
) | ||
assert payload["headers"]["Authorization"] == f"Bearer mock-token" | ||
|
||
# Everything is optional in proto3 as far as the runtime is concerned, | ||
# and we are mocking out the actual API, so just send an empty request. | ||
request = request_type() | ||
|
||
# Mock the actual call within the gRPC stub, and fake the request. | ||
with mock.patch.object(type(client.transport.list_clusters), "__call__") as call: | ||
# Designate an appropriate return value for the call. | ||
call.return_value = clusters.ListClustersResponse( | ||
next_page_token="next_page_token_value", | ||
) | ||
response = client.list_clusters(request) | ||
|
||
# Establish that the underlying gRPC stub method was called. | ||
assert len(call.mock_calls) == 1 | ||
_, args, _ = call.mock_calls[0] | ||
request = clusters.ListClustersRequest() | ||
assert args[0] == request | ||
|
||
# Establish that the response is the type that we expect. | ||
assert isinstance(response, pagers.ListClustersPager) | ||
assert response.next_page_token == "next_page_token_value" | ||
|
||
|
||
async def test_list_runtime(monkeypatch, jp_fetch): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call needs to still be in the updated test. This is the entire point of the test.