Skip to content

Commit bd9d5e9

Browse files
committed
apparently one cannot simply overload a constructor in python
1 parent 49b7903 commit bd9d5e9

2 files changed

Lines changed: 32 additions & 26 deletions

File tree

datacrunch/volumes/volumes.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,6 @@ def __init__(self,
5858
self._instance_id = instance_id
5959
self._ssh_key_ids = ssh_key_ids
6060

61-
# overloading of the init method, initializing the Volume from a dictionary
62-
def __init__(self, volume_dict) -> None:
63-
"""Initialize the volume object from a dictionary
64-
65-
:param volume_dict: volume dictionary
66-
:type volume_dict: dict
67-
"""
68-
self._id = volume_dict['id']
69-
self._status = volume_dict['status']
70-
self._name = volume_dict['name']
71-
self._size = volume_dict['size']
72-
self._type = volume_dict['type']
73-
self._is_os_volume = volume_dict['is_os_volume']
74-
self._created_at = volume_dict['created_at']
75-
self._target = volume_dict['target'] if 'target' in volume_dict else None
76-
self._location = volume_dict['location']
77-
self._instance_id = volume_dict['instance_id'] if 'instance_id' in volume_dict else None
78-
self._ssh_key_ids = volume_dict['ssh_key_ids'] if 'ssh_key_ids' in volume_dict else [
79-
]
80-
8161
@property
8262
def id(self) -> str:
8363
"""Get the volume id
@@ -202,8 +182,20 @@ def get(self, status: str = None) -> List[Volume]:
202182
"""
203183
volumes_dict = self._http_client.get(
204184
VOLUMES_ENDPOINT, params={'status': status}).json()
205-
volumes = list(
206-
map(lambda volume_dict: Volume(volume_dict), volumes_dict))
185+
volumes = list(map(lambda volume_dict: Volume(
186+
id=volume_dict['id'],
187+
status=volume_dict['status'],
188+
name=volume_dict['name'],
189+
size=volume_dict['size'],
190+
type=volume_dict['type'],
191+
is_os_volume=volume_dict['is_os_volume'],
192+
created_at=volume_dict['created_at'],
193+
target=volume_dict['target'] if 'target' in volume_dict else None,
194+
location=volume_dict['location'],
195+
instance_id=volume_dict['instance_id'] if 'instance_id' in volume_dict else None,
196+
ssh_key_ids=volume_dict['ssh_key_ids'] if 'ssh_key_ids' in volume_dict else [
197+
],
198+
), volumes_dict))
207199
return volumes
208200

209201
def get_by_id(self, id: str) -> Volume:
@@ -216,7 +208,21 @@ def get_by_id(self, id: str) -> Volume:
216208
"""
217209
volume_dict = self._http_client.get(
218210
VOLUMES_ENDPOINT + f'/{id}').json()
219-
return Volume(volume_dict)
211+
volume = Volume(
212+
id=volume_dict['id'],
213+
status=volume_dict['status'],
214+
name=volume_dict['name'],
215+
size=volume_dict['size'],
216+
type=volume_dict['type'],
217+
is_os_volume=volume_dict['is_os_volume'],
218+
created_at=volume_dict['created_at'],
219+
target=volume_dict['target'] if 'target' in volume_dict else None,
220+
location=volume_dict['location'],
221+
instance_id=volume_dict['instance_id'] if 'instance_id' in volume_dict else None,
222+
ssh_key_ids=volume_dict['ssh_key_ids'] if 'ssh_key_ids' in volume_dict else [
223+
],
224+
)
225+
return volume
220226

221227
def create(self,
222228
type: str,

tests/unit_tests/volumes/test_volumes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def volumes_service(self, http_client):
7272
def endpoint(self, http_client):
7373
return http_client._base_url + "/volumes"
7474

75-
def test_initialize_a_volume_object_from_arguments(self):
76-
volume = Volume(id=RANDOM_VOL_ID, status=VolumeStatus.DETACHED, instance_id=None, name=HDD_VOL_NAME, size=HDD_VOL_SIZE,
77-
type=HDD, location=FIN1, is_os_volume=False, created_at=HDD_VOL_CREATED_AT, target=None, ssh_key_ids=[])
75+
def test_initialize_a_volume(self):
76+
volume = Volume(RANDOM_VOL_ID, VolumeStatus.DETACHED, HDD_VOL_NAME, HDD_VOL_SIZE,
77+
HDD, False, HDD_VOL_CREATED_AT)
7878

7979
assert volume.id == RANDOM_VOL_ID
8080
assert volume.status == VolumeStatus.DETACHED

0 commit comments

Comments
 (0)