Skip to content

Commit 236018c

Browse files
committed
fixed bug and added test case
1 parent cd18490 commit 236018c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

datacrunch/instances/instances.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,6 @@ def is_available(self, instance_type: str, is_spot: bool = None) -> bool:
428428
:return: True if available to deploy, False otherwise
429429
:rtype: bool
430430
"""
431-
query_param = 'true' if is_spot else 'false'
432-
url = f'/instance-availability/{instance_type}?isSpot={query_param}'
431+
query_param = '?isSpot=true' if is_spot else ''
432+
url = f'/instance-availability/{instance_type}{query_param}'
433433
return self._http_client.get(url).json()

tests/unit_tests/instances/test_instances.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,23 @@ def test_is_available_successful(self, instances_service):
439439
assert is_available is True
440440
assert responses.assert_call_count(url, 1) is True
441441

442+
def test_is_spot_available_successful(self, instances_service):
443+
# arrange - add response mock
444+
url = instances_service._http_client._base_url + '/instance-availability/' + INSTANCE_TYPE + '?isSpot=true'
445+
responses.add(
446+
responses.GET,
447+
url,
448+
json=True,
449+
status=200
450+
)
451+
452+
# act
453+
is_available = instances_service.is_available(INSTANCE_TYPE, is_spot=True)
454+
455+
# assert
456+
assert is_available is True
457+
assert responses.assert_call_count(url, 1) is True
458+
442459
def test_is_available_failed(self, instances_service):
443460
# arrange - add response mock
444461
url = instances_service._http_client._base_url + '/instance-availability/x'

0 commit comments

Comments
 (0)