Skip to content

Commit

Permalink
implement bin/get_current_product_for_app
Browse files Browse the repository at this point in the history
  • Loading branch information
vdloo committed May 25, 2024
1 parent 91aaa9e commit 67c8077
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/get_current_product_for_app
1 change: 0 additions & 1 deletion hypernode_api_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions hypernode_api_python/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
37 changes: 37 additions & 0 deletions tests/commands/test_get_current_product_for_app.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 67c8077

Please sign in to comment.