Skip to content

Commit def759a

Browse files
committed
use the constant value as default location, refactor to location_code
1 parent 29ac719 commit def759a

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

datacrunch/instances/instances.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import List, Union, Optional, Dict
22
from datacrunch.helpers import stringify_class_object_properties
3+
from datacrunch.constants import Locations
34

45
INSTANCES_ENDPOINT = '/instances'
56

@@ -24,7 +25,7 @@ def __init__(self,
2425
storage: dict,
2526
os_volume_id: str,
2627
gpu_memory: dict,
27-
location: str = "FIN-01",
28+
location: str = Locations.FIN_01,
2829
startup_script_id: str = None,
2930
is_spot: bool = False
3031
) -> None:
@@ -392,7 +393,7 @@ def create(self,
392393
"startup_script_id": startup_script_id,
393394
"hostname": hostname,
394395
"description": description,
395-
"location": location,
396+
"location_code": location,
396397
"os_volume": os_volume,
397398
"volumes": volumes,
398399
"existing_volumes": existing_volumes,

datacrunch/volumes/volumes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List, Union, Optional
2-
from datacrunch.constants import VolumeActions
2+
from datacrunch.constants import VolumeActions, Locations
33
from datacrunch.helpers import stringify_class_object_properties
44

55
VOLUMES_ENDPOINT = '/volumes'
@@ -17,7 +17,7 @@ def __init__(self,
1717
is_os_volume: bool,
1818
created_at: str,
1919
target: str = None,
20-
location: str = "FIN-01",
20+
location: str = Locations.FIN_01,
2121
instance_id: str = None,
2222
ssh_key_ids: List[str] = [],
2323
deleted_at: str = None,
@@ -260,7 +260,7 @@ def create(self,
260260
"name": name,
261261
"size": size,
262262
"instance_id": instance_id,
263-
"location": location
263+
"location_code": location
264264
}
265265
id = self._http_client.post(VOLUMES_ENDPOINT, json=payload).text
266266
volume = self.get_by_id(id)

tests/unit_tests/instances/test_instances.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"hostname": INSTANCE_HOSTNAME,
5252
"description": INSTANCE_DESCRIPTION,
53-
"location": INSTANCE_LOCATION,
53+
"location_code": INSTANCE_LOCATION,
5454
"price_per_hour": INSTANCE_PRICE_PER_HOUR,
5555
"instance_type": INSTANCE_TYPE,
5656
"image": INSTANCE_IMAGE,
@@ -63,6 +63,7 @@
6363
PAYLOAD_SPOT = PAYLOAD
6464
PAYLOAD_SPOT[0]["is_spot"] = True
6565

66+
6667
class TestInstancesService:
6768
@pytest.fixture
6869
def instances_service(self, http_client):
@@ -397,7 +398,8 @@ def test_action_successful(self, instances_service, endpoint):
397398
)
398399

399400
# act
400-
result = instances_service.action(id_list=[INSTANCE_ID], action=Actions.SHUTDOWN)
401+
result = instances_service.action(
402+
id_list=[INSTANCE_ID], action=Actions.SHUTDOWN)
401403

402404
# assert
403405
assert result is None
@@ -415,7 +417,8 @@ def test_action_failed(self, instances_service, endpoint):
415417

416418
# act
417419
with pytest.raises(APIException) as excinfo:
418-
instances_service.action(id_list=[INSTANCE_ID], action="fluxturcate")
420+
instances_service.action(
421+
id_list=[INSTANCE_ID], action="fluxturcate")
419422

420423
# assert
421424
assert excinfo.value.code == INVALID_REQUEST
@@ -424,7 +427,8 @@ def test_action_failed(self, instances_service, endpoint):
424427

425428
def test_is_available_successful(self, instances_service):
426429
# arrange - add response mock
427-
url = instances_service._http_client._base_url + '/instance-availability/' + INSTANCE_TYPE
430+
url = instances_service._http_client._base_url + \
431+
'/instance-availability/' + INSTANCE_TYPE
428432
responses.add(
429433
responses.GET,
430434
url,
@@ -441,7 +445,8 @@ def test_is_available_successful(self, instances_service):
441445

442446
def test_is_spot_available_successful(self, instances_service):
443447
# arrange - add response mock
444-
url = instances_service._http_client._base_url + '/instance-availability/' + INSTANCE_TYPE + '?isSpot=true'
448+
url = instances_service._http_client._base_url + \
449+
'/instance-availability/' + INSTANCE_TYPE + '?isSpot=true'
445450
responses.add(
446451
responses.GET,
447452
url,
@@ -450,7 +455,8 @@ def test_is_spot_available_successful(self, instances_service):
450455
)
451456

452457
# act
453-
is_available = instances_service.is_available(INSTANCE_TYPE, is_spot=True)
458+
is_available = instances_service.is_available(
459+
INSTANCE_TYPE, is_spot=True)
454460

455461
# assert
456462
assert is_available is True
@@ -473,4 +479,4 @@ def test_is_available_failed(self, instances_service):
473479
# assert
474480
assert excinfo.value.code == INVALID_REQUEST
475481
assert excinfo.value.message == INVALID_REQUEST_MESSAGE
476-
assert responses.assert_call_count(url, 1) is True
482+
assert responses.assert_call_count(url, 1) is True

tests/unit_tests/volumes/test_volumes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"name": NVME_VOL_NAME,
4040
"size": NVME_VOL_SIZE,
4141
"type": NVME,
42-
"location": FIN1,
42+
"location_code": FIN1,
4343
"is_os_volume": True,
4444
"created_at": NVME_VOL_CREATED_AT,
4545
"target": TARGET_VDA,
@@ -53,7 +53,7 @@
5353
"name": HDD_VOL_NAME,
5454
"size": HDD_VOL_SIZE,
5555
"type": HDD,
56-
"location": FIN1,
56+
"location_code": FIN1,
5757
"is_os_volume": False,
5858
"created_at": HDD_VOL_CREATED_AT,
5959
"target": None,

0 commit comments

Comments
 (0)