Skip to content
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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
14a7916
list and get cluster temporary changes
Jeyaprakash-NK Apr 15, 2024
75e1576
Merge branch 'main' of https://github.com/Shubha-accenture/dataproc-j…
Jeyaprakash-NK Apr 15, 2024
c8f9643
Merge branch 'main' of https://github.com/Shubha-accenture/dataproc-j…
Jeyaprakash-NK Apr 16, 2024
654b621
cluster service BE code change
Jeyaprakash-NK Apr 16, 2024
9659c02
list cluster client library temp changes
Jeyaprakash-NK Apr 17, 2024
3708794
list and get cluster api status changes
Jeyaprakash-NK Aug 8, 2024
25e25c1
stop cluster BE and FE temp changes
Jeyaprakash-NK Aug 12, 2024
cdec0d7
controller rename changes
Jeyaprakash-NK Aug 12, 2024
2a37f2c
latest pull from main and conflicts resolved
Jeyaprakash-NK Aug 12, 2024
d539d90
start cluster and BE temp changes
Jeyaprakash-NK Aug 12, 2024
1d60038
Service file rename changes
Jeyaprakash-NK Aug 12, 2024
611fbac
Merge branch 'main' of https://github.com/Shubha-accenture/dataproc-j…
Jeyaprakash-NK Aug 14, 2024
cd84677
delete cluster and auth access token fix
Jeyaprakash-NK Aug 19, 2024
2b7b95b
await changes in start, stop, delete
Jeyaprakash-NK Aug 19, 2024
9b71492
delete cluster empty handled
Jeyaprakash-NK Aug 19, 2024
312902a
added new dependency "google-cloud-dataproc"
Jeyaprakash-NK Aug 20, 2024
68c21db
code cleanup
Jeyaprakash-NK Aug 22, 2024
4d70971
Code review comments fix
Jeyaprakash-NK Sep 5, 2024
65d004f
pull from main and conflicts resolved
Jeyaprakash-NK Sep 6, 2024
2eb3d98
package conflicts resolved in pyproject
Jeyaprakash-NK Sep 6, 2024
cb818d0
Code review feedback changes BE and FE
Jeyaprakash-NK Sep 6, 2024
8a6072a
line space removed
Jeyaprakash-NK Sep 6, 2024
c5ae698
api endpoint changes in client library
Jeyaprakash-NK Sep 6, 2024
6daa124
prettier changes
Jeyaprakash-NK Sep 6, 2024
7f64795
runtime list code review fix
Jeyaprakash-NK Sep 9, 2024
50f2d2d
Merge branch 'main' of https://github.com/Shubha-accenture/dataproc-j…
Jeyaprakash-NK Sep 11, 2024
a734f1e
changed all package versions >= instead ~=
Jeyaprakash-NK Sep 12, 2024
ff65fda
code format fix python
Jeyaprakash-NK Sep 12, 2024
7580728
pyproject version change
Jeyaprakash-NK Sep 13, 2024
36dfd9e
pyproject change '>=' from '~='
Jeyaprakash-NK Sep 13, 2024
a3edf3d
client library test for list cluster
Jeyaprakash-NK Sep 16, 2024
d8e3567
aioHttp pyproject version change
Jeyaprakash-NK Sep 16, 2024
f87ce93
list cluster revert changes test
Jeyaprakash-NK Sep 16, 2024
f656955
test changes for list cluster
Jeyaprakash-NK Sep 16, 2024
218ecde
list cluster test file changes
Jeyaprakash-NK Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions dataproc_jupyter_plugin/tests/test_dataproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)
Copy link
Contributor

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.

assert response.code == 200
payload = json.loads(response.body)
Copy link
Contributor

Choose a reason for hiding this comment

The 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"):
Copy link
Contributor

Choose a reason for hiding this comment

The 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 jp_fetch method used to hit the /dataproc-plugin/clusterList endpoint, and the response from that call needs to be inspected to verify that it actually called into the underlying API client.

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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"pendulum>=3.0.0",
"pydantic>=1.10.0",
"bigframes>=0.22.0",
"aiohttp>=3.9.5",
"aiohttp~=3.9.5",
"google-cloud-dataproc>=5.10.2",
"google-cloud-storage>=2.18.2"
]
Expand Down
Loading