diff --git a/hypernode_api_python/client.py b/hypernode_api_python/client.py index 4bfbb13..c35d874 100644 --- a/hypernode_api_python/client.py +++ b/hypernode_api_python/client.py @@ -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/" @@ -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 diff --git a/tests/client/test_get_sla.py b/tests/client/test_get_sla.py new file mode 100644 index 0000000..02a0487 --- /dev/null +++ b/tests/client/test_get_sla.py @@ -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)