Skip to content

Commit 7f86615

Browse files
author
Ruslan Gainutdinov
committed
fix: format, lint and unit test fixing
1 parent 99668e8 commit 7f86615

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

tests/integration_tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Make sure to run the server and the account has enough balance before running the tests
1010
"""
1111

12-
BASE_URL = os.getenv('VERDA_BASE_URL', 'https://api.verda.com/v1')
12+
BASE_URL = 'http://localhost:3010/v1'
1313

1414
# Load env variables, make sure there's an env file with valid client credentials
1515
load_dotenv()

tests/unit_tests/clusters/test_clusters.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import responses # https://github.com/getsentry/responses
33

4-
from verda.clusters import Cluster, ClusterWorkerNode, ClustersService
4+
from verda.clusters import Cluster, ClustersService, ClusterWorkerNode
55
from verda.constants import ErrorCodes, Locations
66
from verda.exceptions import APIException
77

@@ -95,7 +95,7 @@ def test_get_clusters(self, clusters_service, endpoint):
9595
def test_create_cluster_successful(self, clusters_service, endpoint):
9696
# arrange - add response mock
9797
# create cluster
98-
responses.add(responses.POST, endpoint, body=CLUSTER_ID, status=200)
98+
responses.add(responses.POST, endpoint, json={'id': CLUSTER_ID}, status=200)
9999
# get cluster by id
100100
url = endpoint + '/' + CLUSTER_ID
101101
responses.add(responses.GET, url, json=CLUSTER_PAYLOAD[0], status=200)
@@ -117,7 +117,7 @@ def test_create_cluster_successful(self, clusters_service, endpoint):
117117
assert cluster.description == CLUSTER_DESCRIPTION
118118
assert cluster.status == CLUSTER_STATUS
119119
assert cluster.cluster_type == CLUSTER_CLUSTER_TYPE
120-
assert cluster.node_count == CLUSTER_NODE_COUNT
120+
assert len(cluster.worker_nodes) == CLUSTER_NODE_COUNT
121121
assert cluster.ssh_key_ids == [SSH_KEY_ID]
122122
assert cluster.location == CLUSTER_LOCATION
123123
assert cluster.image == CLUSTER_IMAGE
@@ -136,11 +136,12 @@ def test_create_cluster_failed(self, clusters_service, endpoint):
136136
# act
137137
with pytest.raises(APIException) as excinfo:
138138
clusters_service.create(
139-
name=CLUSTER_HOSTNAME,
139+
hostname=CLUSTER_HOSTNAME,
140140
cluster_type=CLUSTER_CLUSTER_TYPE,
141-
node_count=CLUSTER_NODE_COUNT,
142141
image=CLUSTER_IMAGE,
143142
description=CLUSTER_DESCRIPTION,
143+
ssh_key_ids=[SSH_KEY_ID],
144+
location=CLUSTER_LOCATION,
144145
)
145146

146147
# assert
@@ -150,22 +151,21 @@ def test_create_cluster_failed(self, clusters_service, endpoint):
150151

151152
def test_delete_cluster_successful(self, clusters_service, endpoint):
152153
# arrange - add response mock
153-
url = endpoint + '/' + CLUSTER_ID
154-
responses.add(responses.DELETE, url, status=202)
154+
url = endpoint
155+
responses.add(responses.PUT, url, status=202)
155156

156157
# act
157-
result = clusters_service.action(CLUSTER_ID, 'delete')
158+
result = clusters_service.delete(CLUSTER_ID)
158159

159160
# assert
160161
assert result is None
161162
assert responses.assert_call_count(url, 1) is True
162163

163164
def test_delete_cluster_failed(self, clusters_service, endpoint):
164165
# arrange - add response mock
165-
url = endpoint + '/invalid_id'
166166
responses.add(
167-
responses.DELETE,
168-
url,
167+
responses.PUT,
168+
endpoint,
169169
json={'code': INVALID_REQUEST, 'message': INVALID_REQUEST_MESSAGE},
170170
status=400,
171171
)
@@ -177,5 +177,4 @@ def test_delete_cluster_failed(self, clusters_service, endpoint):
177177
# assert
178178
assert excinfo.value.code == INVALID_REQUEST
179179
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
180-
assert responses.assert_call_count(url, 1) is True
181-
180+
assert responses.assert_call_count(endpoint, 1) is True

verda/clusters/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Clusters service for managing compute clusters."""
22

3-
from verda.clusters._clusters import Cluster, ClusterWorkerNode, ClustersService
3+
from verda.clusters._clusters import Cluster, ClustersService, ClusterWorkerNode
44

55
__all__ = ['Cluster', 'ClusterWorkerNode', 'ClustersService']

verda/clusters/_clusters.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
CLUSTERS_ENDPOINT = '/clusters'
1111

1212

13-
1413
@dataclass_json
1514
@dataclass
1615
class ClusterWorkerNode:
@@ -203,6 +202,15 @@ def action(self, id_list: list[str] | str, action: str) -> None:
203202
self._http_client.put(CLUSTERS_ENDPOINT, json=payload)
204203
return
205204

205+
def delete(self, cluster_id: str) -> None:
206+
"""Deletes a cluster.
207+
208+
Args:
209+
cluster_id: ID of the cluster to delete.
210+
"""
211+
self.action(cluster_id, 'delete')
212+
return
213+
206214
def is_available(
207215
self,
208216
cluster_type: str,

0 commit comments

Comments
 (0)