From 8cb5203c468d4d0d9056b5bec196e763d83c20e3 Mon Sep 17 00:00:00 2001 From: Rick van de Loo Date: Fri, 24 May 2024 16:51:49 +0200 Subject: [PATCH] add get_cluster_relations to api client looks like: ``` In [1]: from hypernode_api_python.client import HypernodeAPIPython In [2]: import os In [3]: client = HypernodeAPIPython(os.environ['MYSECRETAPITOKEN']) In [4]: client.get_cluster_relations("mytestappweb").json() Out[4]: {'parents': [{'id': 182, 'parent': 'mytestappdb', 'child': 'mytestappweb', 'relation_type': 'mysql', 'cluster_description': None}, {'id': 180, 'parent': 'mytestapp', 'child': 'mytestappweb', 'relation_type': 'loadbalancer', 'cluster_description': None}, {'id': 181, 'parent': 'mytestapp', 'child': 'mytestappweb', 'relation_type': 'nfs', 'cluster_description': None}], 'children': []} ``` --- hypernode_api_python/client.py | 29 ++++++++++++++++++++++ tests/client/test_get_cluster_relations.py | 28 +++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/client/test_get_cluster_relations.py diff --git a/hypernode_api_python/client.py b/hypernode_api_python/client.py index 9b3aa98..4bfbb13 100644 --- a/hypernode_api_python/client.py +++ b/hypernode_api_python/client.py @@ -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/" @@ -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 diff --git a/tests/client/test_get_cluster_relations.py b/tests/client/test_get_cluster_relations.py new file mode 100644 index 0000000..4b5b7ec --- /dev/null +++ b/tests/client/test_get_cluster_relations.py @@ -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)