Skip to content

add get_cluster_relations to api client #23

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

Merged
merged 1 commit into from
May 24, 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
29 changes: 29 additions & 0 deletions hypernode_api_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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/"
HYPERNODE_API_APP_CLUSTER_RELATIONS = "/v2/app/{}/relations/"
HYPERNODE_API_APP_DETAIL_ENDPOINT = "/v2/app/{}/?destroyed=false"
HYPERNODE_API_APP_DETAIL_WITH_ADDONS_ENDPOINT = "/v2/app/{}/with_addons?destroyed=false"
HYPERNODE_API_APP_EAV_DESCRIPTION_ENDPOINT = "/v2/app/eav_descriptions/"
Expand Down Expand Up @@ -365,6 +366,34 @@ def get_app_configurations(self):
"""
return self.requests("GET", HYPERNODE_API_APP_CONFIGURATION_ENDPOINT)

def get_cluster_relations(self, app_name):
""" "
List all relations for the specified app. This will return all the
relations that are currently configured for the specified app.

Example:
> client.get_cluster_relations('mytestappweb').json()
> {'children': [],
> 'parents': [{'child': 'mytestappweb',
> 'cluster_description': None,
> 'id': 182,
> 'parent': 'mytestappdb',
> 'relation_type': 'mysql'},
> {'child': 'mytestappweb',
> 'cluster_description': None,
> 'id': 180,
> 'parent': 'mytestapp',
> 'relation_type': 'loadbalancer'},
> {'child': 'mytestappweb',
> 'cluster_description': None,
> 'id': 181,
> 'parent': 'mytestapp',
> 'relation_type': 'nfs'}]}
"""
return self.requests(
"GET", HYPERNODE_API_APP_CLUSTER_RELATIONS.format(app_name)
)

def get_product_info_with_price(self, product_code, error_to_raise=None):
"""
Get information about a specific product
Expand Down
28 changes: 28 additions & 0 deletions tests/client/test_get_cluster_relations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest.mock import Mock

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


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

def test_calls_hypernode_api_cluster_relations_endpoint_with_correct_parameters(
self,
):
self.client.get_cluster_relations("yourhypernodeappname")

self.mock_request.assert_called_once_with(
"GET", HYPERNODE_API_APP_CLUSTER_RELATIONS.format("yourhypernodeappname")
)

def test_returns_result_for_hypernode_api_cluster_relations(self):
ret = self.client.get_cluster_relations("yourhypernodeappname")

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