11import pytest
22import responses # https://github.com/getsentry/responses
33
4- from verda .clusters import Cluster , ClusterWorkerNode , ClustersService
4+ from verda .clusters import Cluster , ClustersService , ClusterWorkerNode
55from verda .constants import ErrorCodes , Locations
66from 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
0 commit comments