Skip to content

Commit ed533a1

Browse files
feat: Add helper function for creating a brancher in hypernode-api
1 parent 49adf30 commit ed533a1

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

hypernode_api_python/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
HYPERNODE_API_APP_DETAIL_WITH_ADDONS_ENDPOINT = "/v2/app/{}/with_addons?destroyed=false"
1010
HYPERNODE_API_APP_EAV_DESCRIPTION_ENDPOINT = "/v2/app/eav_descriptions/"
1111
HYPERNODE_API_APP_FLAVOR_ENDPOINT = "/v2/app/{}/flavor/"
12+
HYPERNODE_API_APP_BRANCHER_ENDPOINT = "/v2/app/{}/brancher/"
1213
HYPERNODE_API_APP_NEXT_BEST_PLAN_ENDPOINT = "/v2/app/{}/next_best_plan/"
1314
HYPERNODE_API_APP_PRODUCT_LIST_ENDPOINT = "/v2/product/app/{}/"
1415
HYPERNODE_API_APP_XGRADE_CHECK_ENDPOINT = "/v2/app/xgrade/{}/check/{}/"
@@ -628,3 +629,16 @@ def order_hypernode(self, data):
628629
:return obj response: The request response object
629630
"""
630631
return self.requests("POST", HYPERNODE_API_APP_ORDER_ENDPOINT, data=data)
632+
633+
def create_brancher(self, app_name, data):
634+
"""
635+
Create a new branch (server replica) of your Hypernode.
636+
637+
:param str app_name: The name of the Hypernode to create the branch from
638+
:param dict data: Data regarding the branch to be created. An example could be:
639+
{'clear': 'mysql'}.
640+
:return obj response: The request response object
641+
"""
642+
return self.requests(
643+
"POST", HYPERNODE_API_APP_BRANCHER_ENDPOINT.format(app_name), data=data
644+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from unittest import TestCase
2+
from unittest.mock import Mock
3+
4+
from hypernode_api_python.client import (
5+
HYPERNODE_API_APP_BRANCHER_ENDPOINT,
6+
HypernodeAPIPython,
7+
)
8+
9+
10+
class TestCreateBrancher(TestCase):
11+
def setUp(self):
12+
self.client = HypernodeAPIPython(token="my_token")
13+
self.mock_request = Mock()
14+
self.client.requests = self.mock_request
15+
self.app_name = "my_app"
16+
17+
def test_brancher_endpoint_is_correct(self):
18+
self.assertEqual("/v2/app/{}/brancher/", HYPERNODE_API_APP_BRANCHER_ENDPOINT)
19+
20+
def test_calls_create_brancher_endpoint_properly(self):
21+
data = {"clear_services": ["mysql"]}
22+
self.client.create_brancher(self.app_name, data)
23+
24+
self.mock_request.assert_called_once_with(
25+
"POST", f"/v2/app/{self.app_name}/brancher/", data=data
26+
)
27+
28+
def test_returns_create_brancher_data(self):
29+
response = Mock()
30+
response.status_code = 200
31+
self.mock_request.return_value = response
32+
33+
self.assertEqual(
34+
self.client.create_brancher(self.app_name, {}),
35+
self.mock_request.return_value,
36+
)

0 commit comments

Comments
 (0)