|
60 | 60 | } |
61 | 61 | ] |
62 | 62 |
|
| 63 | +PAYLOAD_SPOT = PAYLOAD |
| 64 | +PAYLOAD_SPOT[0]["is_spot"] = True |
63 | 65 |
|
64 | 66 | class TestInstancesService: |
65 | 67 | @pytest.fixture |
@@ -261,6 +263,57 @@ def test_create_instance_successful(self, instances_service, endpoint): |
261 | 263 | assert responses.assert_call_count(endpoint, 1) is True |
262 | 264 | assert responses.assert_call_count(url, 1) is True |
263 | 265 |
|
| 266 | + def test_create_spot_instance_successful(self, instances_service, endpoint): |
| 267 | + # arrange - add response mock |
| 268 | + # add response mock for the create instance endpoint |
| 269 | + responses.add( |
| 270 | + responses.POST, |
| 271 | + endpoint, |
| 272 | + body=INSTANCE_ID, |
| 273 | + status=200 |
| 274 | + ) |
| 275 | + # add response mock for the get instance by id endpoint |
| 276 | + url = endpoint + '/' + INSTANCE_ID |
| 277 | + responses.add( |
| 278 | + responses.GET, |
| 279 | + url, |
| 280 | + json=PAYLOAD_SPOT[0], |
| 281 | + status=200 |
| 282 | + ) |
| 283 | + |
| 284 | + # act |
| 285 | + instance = instances_service.create( |
| 286 | + instance_type=INSTANCE_TYPE, |
| 287 | + image=INSTANCE_IMAGE, |
| 288 | + ssh_key_ids=[SSH_KEY_ID], |
| 289 | + hostname=INSTANCE_HOSTNAME, |
| 290 | + description=INSTANCE_DESCRIPTION, |
| 291 | + os_volume=INSTANCE_OS_VOLUME |
| 292 | + ) |
| 293 | + |
| 294 | + # assert |
| 295 | + assert type(instance) == Instance |
| 296 | + assert instance.id == INSTANCE_ID |
| 297 | + assert instance.ssh_key_ids == [SSH_KEY_ID] |
| 298 | + assert instance.status == INSTANCE_STATUS |
| 299 | + assert instance.image == INSTANCE_IMAGE |
| 300 | + assert instance.instance_type == INSTANCE_TYPE |
| 301 | + assert instance.price_per_hour == INSTANCE_PRICE_PER_HOUR |
| 302 | + assert instance.location == INSTANCE_LOCATION |
| 303 | + assert instance.description == INSTANCE_DESCRIPTION |
| 304 | + assert instance.hostname == INSTANCE_HOSTNAME |
| 305 | + assert instance.ip == INSTANCE_IP |
| 306 | + assert instance.created_at == INSTANCE_CREATED_AT |
| 307 | + assert instance.os_volume_id == OS_VOLUME_ID |
| 308 | + assert instance.is_spot == True |
| 309 | + assert type(instance.cpu) == dict |
| 310 | + assert type(instance.gpu) == dict |
| 311 | + assert type(instance.memory) == dict |
| 312 | + assert type(instance.gpu_memory) == dict |
| 313 | + assert type(instance.storage) == dict |
| 314 | + assert responses.assert_call_count(endpoint, 1) is True |
| 315 | + assert responses.assert_call_count(url, 1) is True |
| 316 | + |
264 | 317 | def test_create_instance_attached_os_volume_successful(self, instances_service, endpoint): |
265 | 318 | # arrange - add response mock |
266 | 319 | # create instance |
|
0 commit comments