Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion gradient/api_sdk/repositories/machine_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ def get_request_url(self, **kwargs):
def _get_api_url(self, **kwargs):
return config.config.CONFIG_HOST

def _get_request_params(self, kwargs):
return {'includePublicClusters': 'true'}

def _get_instance_dicts(self, data, cluster_id=None, **kwargs):
vm_types_dicts = {} # vmType["label"]: vmType dict
for cluster_list_of_vms in data.values():
current_cluster_id = cluster_list_of_vms[0]["clusters"][0]["id"]

for vm in cluster_list_of_vms:
if not vm["isAvailable"]:
continue
vm_type = vm["vmType"]
vm_type_label = vm_type["label"]
vm_types_dicts.setdefault(vm_type_label, vm_type)

clusters = vm_types_dicts[vm_type_label].setdefault("clusters", [])
clusters = vm_types_dicts[vm_type_label].setdefault(
"clusters", [])
if current_cluster_id not in clusters:
clusters.append(current_cluster_id)

Expand Down
11 changes: 6 additions & 5 deletions tests/functional/test_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class TestListVmTypes(object):

RESPONSE_JSON_WHEN_WRONG_API_KEY_WAS_USED = {"status": 400, "message": "Invalid API token"}
EXPECTED_STDOUT_WHEN_WRONG_API_KEY_WAS_USED = "Failed to fetch data: Invalid API token\n"
DEFAULT_PARAMS = {'includePublicClusters': 'true'}

@mock.patch("gradient.api_sdk.clients.http_client.requests.get")
def test_should_send_get_request_and_print_list_of_machine_types(self, get_patched):
Expand All @@ -139,7 +140,7 @@ def test_should_send_get_request_and_print_list_of_machine_types(self, get_patch
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

assert EXPECTED_HEADERS["X-API-Key"] != "some_key"

Expand All @@ -154,7 +155,7 @@ def test_should_send_get_request_and_print_list_of_vm_machine_types_filtered_by_
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

@mock.patch("gradient.api_sdk.clients.http_client.requests.get")
def test_should_send_get_request_and_print_list_of_machine_types_but_none_found(self, get_patched):
Expand All @@ -166,7 +167,7 @@ def test_should_send_get_request_and_print_list_of_machine_types_but_none_found(
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

assert result.output == "No data found\n"

Expand All @@ -181,7 +182,7 @@ def test_should_print_proper_message_when_wrong_api_key_was_used(self, get_patch
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS,
json=None,
params=None)
params=self.DEFAULT_PARAMS)

assert result.output == self.EXPECTED_STDOUT_WHEN_WRONG_API_KEY_WAS_USED
assert EXPECTED_HEADERS["X-API-Key"] != "some_key"
Expand All @@ -198,4 +199,4 @@ def test_should_read_options_defined_in_a_config_file(self, get_patched, vm_mach
get_patched.assert_called_once_with(self.URL,
headers=EXPECTED_HEADERS_WITH_CHANGED_API_KEY,
json=None,
params=None)
params=self.DEFAULT_PARAMS)