Skip to content

Commit

Permalink
implement get_sla method
Browse files Browse the repository at this point in the history
for getting a specific SLA
  • Loading branch information
vdloo committed May 25, 2024
1 parent 71ba502 commit 992dd53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hypernode_api_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

DEFAULT_USER_AGENT = "hypernode-api-python"
HYPERNODE_API_URL = "https://api.hypernode.com"
HYPERNODE_API_ADDON_LIST_ENDPOINT = "/v2/addon/"
HYPERNODE_API_ADDON_SLA_LIST_ENDPOINT = "/v2/addon/slas/"
HYPERNODE_API_APP_CHECK_PAYMENT_INFORMATION = "/v2/app/{}/check-payment-information/"
HYPERNODE_API_APP_CONFIGURATION_ENDPOINT = "/v2/configuration/"
Expand Down Expand Up @@ -272,6 +273,22 @@ def get_slas(self):
"""
return self.requests("GET", HYPERNODE_API_ADDON_SLA_LIST_ENDPOINT)

def get_sla(self, sla_code):
"""
List a specific SLA
Example:
> client.get_sla("sla-standard").json()
> {'billing_period': 1,
> 'billing_period_unit': 'month',
> 'code': 'sla-standard',
> 'id': 123,
> 'name': 'SLA Standard',
> 'price': 1234}
:return obj response: The request response object
"""
return self.requests("GET", HYPERNODE_API_ADDON_LIST_ENDPOINT + sla_code + "/")

def get_available_backups_for_app(self, app_name):
"""
Lists the available backups for the specified app
Expand Down
26 changes: 26 additions & 0 deletions tests/client/test_get_sla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from unittest.mock import Mock

from tests.testcase import TestCase
from hypernode_api_python.client import (
HypernodeAPIPython,
HYPERNODE_API_ADDON_LIST_ENDPOINT,
)


class TestGetSla(TestCase):
def setUp(self):
self.mock_request = Mock()
self.client = HypernodeAPIPython(token="mytoken")
self.client.requests = self.mock_request

def test_calls_hypernode_api_endpoint_with_correct_parameters(self):
self.client.get_sla("sla-standard")

self.mock_request.assert_called_once_with(
"GET", HYPERNODE_API_ADDON_LIST_ENDPOINT + "sla-standard/"
)

def test_returns_json_result(self):
ret = self.client.get_sla("sla-standard")

self.assertEqual(ret, self.mock_request.return_value)

0 comments on commit 992dd53

Please sign in to comment.