Skip to content

Commit 4aa7ef2

Browse files
authored
Merge pull request #25 from ByteInternet/add-get-sla-method
implement get_sla method
2 parents 71ba502 + 992dd53 commit 4aa7ef2

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Diff for: hypernode_api_python/client.py

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
DEFAULT_USER_AGENT = "hypernode-api-python"
44
HYPERNODE_API_URL = "https://api.hypernode.com"
5+
HYPERNODE_API_ADDON_LIST_ENDPOINT = "/v2/addon/"
56
HYPERNODE_API_ADDON_SLA_LIST_ENDPOINT = "/v2/addon/slas/"
67
HYPERNODE_API_APP_CHECK_PAYMENT_INFORMATION = "/v2/app/{}/check-payment-information/"
78
HYPERNODE_API_APP_CONFIGURATION_ENDPOINT = "/v2/configuration/"
@@ -272,6 +273,22 @@ def get_slas(self):
272273
"""
273274
return self.requests("GET", HYPERNODE_API_ADDON_SLA_LIST_ENDPOINT)
274275

276+
def get_sla(self, sla_code):
277+
"""
278+
List a specific SLA
279+
Example:
280+
> client.get_sla("sla-standard").json()
281+
> {'billing_period': 1,
282+
> 'billing_period_unit': 'month',
283+
> 'code': 'sla-standard',
284+
> 'id': 123,
285+
> 'name': 'SLA Standard',
286+
> 'price': 1234}
287+
288+
:return obj response: The request response object
289+
"""
290+
return self.requests("GET", HYPERNODE_API_ADDON_LIST_ENDPOINT + sla_code + "/")
291+
275292
def get_available_backups_for_app(self, app_name):
276293
"""
277294
Lists the available backups for the specified app

Diff for: tests/client/test_get_sla.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from unittest.mock import Mock
2+
3+
from tests.testcase import TestCase
4+
from hypernode_api_python.client import (
5+
HypernodeAPIPython,
6+
HYPERNODE_API_ADDON_LIST_ENDPOINT,
7+
)
8+
9+
10+
class TestGetSla(TestCase):
11+
def setUp(self):
12+
self.mock_request = Mock()
13+
self.client = HypernodeAPIPython(token="mytoken")
14+
self.client.requests = self.mock_request
15+
16+
def test_calls_hypernode_api_endpoint_with_correct_parameters(self):
17+
self.client.get_sla("sla-standard")
18+
19+
self.mock_request.assert_called_once_with(
20+
"GET", HYPERNODE_API_ADDON_LIST_ENDPOINT + "sla-standard/"
21+
)
22+
23+
def test_returns_json_result(self):
24+
ret = self.client.get_sla("sla-standard")
25+
26+
self.assertEqual(ret, self.mock_request.return_value)

0 commit comments

Comments
 (0)