From 67c8077cd484780b44ff607c94d562a90c95dbc5 Mon Sep 17 00:00:00 2001 From: Rick van de Loo Date: Sat, 25 May 2024 15:58:14 +0200 Subject: [PATCH] implement bin/get_current_product_for_app --- bin/get_current_product_for_app | 1 + hypernode_api_python/client.py | 1 - hypernode_api_python/commands.py | 31 ++++++++++++++++ .../test_get_current_product_for_app.py | 37 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 120000 bin/get_current_product_for_app create mode 100644 tests/commands/test_get_current_product_for_app.py diff --git a/bin/get_current_product_for_app b/bin/get_current_product_for_app new file mode 120000 index 0000000..e42252a --- /dev/null +++ b/bin/get_current_product_for_app @@ -0,0 +1 @@ +command \ No newline at end of file diff --git a/hypernode_api_python/client.py b/hypernode_api_python/client.py index b757fcb..f391d16 100644 --- a/hypernode_api_python/client.py +++ b/hypernode_api_python/client.py @@ -580,7 +580,6 @@ def get_whitelist_rules(self, app_name, filter_data=None): "GET", HYPERNODE_API_WHITELIST_ENDPOINT.format(app_name), filter_data ) - # TODO: add entrypoint for this method in bin/ and commands.py def get_current_product_for_app(self, app_name): """ Retrieve information about the product the specified App is currently on. diff --git a/hypernode_api_python/commands.py b/hypernode_api_python/commands.py index c945fe4..f0d5a0c 100644 --- a/hypernode_api_python/commands.py +++ b/hypernode_api_python/commands.py @@ -477,3 +477,34 @@ def get_whitelist_rules(args=None): client = get_client() app_name = get_app_name() print_response(client.get_whitelist_rules(app_name)) + + +def get_current_product_for_app(args=None): + parser = ArgumentParser( + description=""" +Gets the current product for the specified app. + +Example: +$ ./bin/get_current_product_for_app +{ + "code": "FALCON_M_202203", + "name": "Falcon M", + "backups_enabled": true, + "is_development": false, + "varnish_supported": true, + "supports_sla": true, + "provider_flavors": [ + { + "vcpus": 3, + "ram_in_mb": 16384, + ... + }, + ... +} +""", + formatter_class=RawTextHelpFormatter, + ) + parser.parse_args(args=args) + client = get_client() + app_name = get_app_name() + print_response(client.get_current_product_for_app(app_name)) diff --git a/tests/commands/test_get_current_product_for_app.py b/tests/commands/test_get_current_product_for_app.py new file mode 100644 index 0000000..e19d9d6 --- /dev/null +++ b/tests/commands/test_get_current_product_for_app.py @@ -0,0 +1,37 @@ +from hypernode_api_python.commands import get_current_product_for_app +from tests.testcase import TestCase + + +class TestGetCurrentProductForApp(TestCase): + def setUp(self): + self.print_response = self.set_up_patch( + "hypernode_api_python.commands.print_response" + ) + self.get_client = self.set_up_patch("hypernode_api_python.commands.get_client") + self.client = self.get_client.return_value + self.get_app_name = self.set_up_patch( + "hypernode_api_python.commands.get_app_name" + ) + self.get_app_name.return_value = "myappname" + + def test_get_current_product_for_app_gets_client(self): + get_current_product_for_app([]) + + self.get_client.assert_called_once_with() + + def test_get_current_product_for_app_gets_app_name(self): + get_current_product_for_app([]) + + self.get_app_name.assert_called_once_with() + + def test_get_current_product_for_app_gets_current_product_for_app(self): + get_current_product_for_app([]) + + self.client.get_current_product_for_app.assert_called_once_with("myappname") + + def test_get_current_product_for_app_prints_current_product_for_app(self): + get_current_product_for_app([]) + + self.print_response.assert_called_once_with( + self.client.get_current_product_for_app.return_value + )