Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement get_sla method #25

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading