Skip to content

Commit 683f53e

Browse files
committed
Initial configuration clusters list tests
1 parent e7f7b83 commit 683f53e

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

tests/example_responses.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6140,3 +6140,51 @@
61406140
},
61416141
"tagFilter": []
61426142
}
6143+
6144+
EXAMPLE_CLUSTERS_LIST_RESPONSE = [
6145+
{
6146+
"id": "cluster_id_1",
6147+
"name": "cluster name 1",
6148+
"type": "Job Cluster",
6149+
"region": "Private",
6150+
"cloud": "private",
6151+
"teamId": "team_id",
6152+
"isDefault": True,
6153+
"dtCreated": "2019-07-05T23:28:17.416Z",
6154+
"dtModified": "2019-07-05T23:28:17.416Z",
6155+
"clusterId": 91,
6156+
"isPrivate": True,
6157+
"modelName": "team",
6158+
"modelId": 1170
6159+
},
6160+
{
6161+
"id": "cluster_id_2",
6162+
"name": "cluster name 2",
6163+
"type": "Kubernetes Processing Site",
6164+
"region": "Private",
6165+
"cloud": "aws",
6166+
"teamId": "team_id",
6167+
"isDefault": False,
6168+
"dtCreated": "2019-07-22T14:50:10.170Z",
6169+
"dtModified": "2019-11-21T18:12:27.723Z",
6170+
"clusterId": 92,
6171+
"isPrivate": True,
6172+
"modelName": "team",
6173+
"modelId": 1170
6174+
},
6175+
{
6176+
"id": "cluster_id_3",
6177+
"name": "cluster name 3",
6178+
"type": "Job Cluster",
6179+
"region": "Private",
6180+
"cloud": "gcp",
6181+
"teamId": "team_id",
6182+
"isDefault": False,
6183+
"dtCreated": "2019-10-29T18:42:50.985Z",
6184+
"dtModified": "2019-11-21T18:12:27.723Z",
6185+
"clusterId": 100,
6186+
"isPrivate": True,
6187+
"modelName": "team",
6188+
"modelId": 1170
6189+
}
6190+
]

tests/functional/test_clusters.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import mock
2+
from click.testing import CliRunner
3+
4+
from gradient.api_sdk.clients import http_client
5+
from gradient.cli import cli
6+
from tests import example_responses, MockResponse
7+
8+
9+
class TestClustersList(object):
10+
URL = "https://api.paperspace.io/clusters/getClusters"
11+
12+
COMMAND = ["clusters", "list"]
13+
COMMAND_WITH_OPTIONS_FILE = ["clusters", "list", "--optionsFile", ] # path added in test
14+
15+
LIST_CLUSTERS = example_responses.EXAMPLE_CLUSTERS_LIST_RESPONSE
16+
17+
DEFAULT_PARAMS = {
18+
"filter": '{"limit": 20, "offset": 0, "where": {"isPrivate": true}}'
19+
}
20+
21+
COMMAND_WITH_API_KEY = ["clusters", "list", "--apiKey", "some_key"]
22+
EXPECTED_HEADERS = http_client.default_headers.copy()
23+
EXPECTED_HEADERS_WITH_CHANGED_API_KEY = http_client.default_headers.copy()
24+
EXPECTED_HEADERS_WITH_CHANGED_API_KEY["X-API-Key"] = "some_key"
25+
26+
LIST_STDOUT = """+--------------+----------------+----------------------------+
27+
| ID | Name | Type |
28+
+--------------+----------------+----------------------------+
29+
| cluster_id_1 | cluster name 1 | Job Cluster |
30+
| cluster_id_2 | cluster name 2 | Kubernetes Processing Site |
31+
| cluster_id_3 | cluster name 3 | Job Cluster |
32+
+--------------+----------------+----------------------------+
33+
"""
34+
35+
@mock.patch("gradient.api_sdk.clients.http_client.requests.get")
36+
def test_should_send_get_request_and_print_list_of_clusters(self, get_patched):
37+
get_patched.return_value = MockResponse(self.LIST_CLUSTERS, 200, "fake content")
38+
39+
runner = CliRunner()
40+
result = runner.invoke(cli.cli, self.COMMAND)
41+
42+
assert self.LIST_STDOUT in result.output, result.exc_info
43+
get_patched.assert_called_once_with(self.URL,
44+
headers=self.EXPECTED_HEADERS,
45+
json=None,
46+
params=self.DEFAULT_PARAMS)

0 commit comments

Comments
 (0)