Skip to content

Commit 992dd53

Browse files
committed
implement get_sla method
for getting a specific SLA
1 parent 71ba502 commit 992dd53

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

‎hypernode_api_python/client.py‎

Lines changed: 17 additions & 0 deletions
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
returnself.requests("GET", HYPERNODE_API_ADDON_SLA_LIST_ENDPOINT)
274275

276+
defget_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+
returnself.requests("GET", HYPERNODE_API_ADDON_LIST_ENDPOINT+sla_code+"/")
291+
275292
defget_available_backups_for_app(self, app_name):
276293
"""
277294
Lists the available backups for the specified app

‎tests/client/test_get_sla.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fromunittest.mockimportMock
2+
3+
fromtests.testcaseimportTestCase
4+
fromhypernode_api_python.clientimport (
5+
HypernodeAPIPython,
6+
HYPERNODE_API_ADDON_LIST_ENDPOINT,
7+
)
8+
9+
10+
classTestGetSla(TestCase):
11+
defsetUp(self):
12+
self.mock_request=Mock()
13+
self.client=HypernodeAPIPython(token="mytoken")
14+
self.client.requests=self.mock_request
15+
16+
deftest_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+
deftest_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)