Skip to content

Commit af86d19

Browse files
Merge pull request #8 from ByteInternet/HNWEB-5220-add-active-branchers-endpoint
HNWEB-5220-add-active-branchers-endpoint
2 parents 53f7868 + 2cf1eb1 commit af86d19

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

hypernode_api_python/client.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,39 @@ def order_hypernode(self, data):
630630
"""
631631
return self.requests("POST", HYPERNODE_API_APP_ORDER_ENDPOINT, data=data)
632632

633+
def get_active_branchers(self, app_name):
634+
"""
635+
List all active brancher nodes of your Hypernode.
636+
Example:
637+
> client.get_active_branchers("yourhypernodeappname").json()
638+
> {
639+
> "monthly_total_time": 6397,
640+
> "monthly_total_cost": 109,
641+
> "branchers": [
642+
> {
643+
> "id": 21,
644+
> "name": "yourhypernodeappname-eph123456",
645+
> "created": "2019-08-24T14:15:22Z"
646+
> "ip": "127.0.0.1",
647+
> "elapsed_time": 7824,
648+
> },
649+
> {
650+
> "id": 22,
651+
> "name": "yourhypernodeappname-eph654321",
652+
> "ip": "52.68.96.58",
653+
> "created": "2019-08-24T14:15:22Z"
654+
> "elapsed_time": 7224,
655+
> }
656+
> ]
657+
> }
658+
659+
:param str app_name: The name of the Hypernode to get your active branchers for
660+
:return obj response: The request response object
661+
"""
662+
return self.requests(
663+
"GET", HYPERNODE_API_APP_BRANCHER_ENDPOINT.format(app_name)
664+
)
665+
633666
def create_brancher(self, app_name, data):
634667
"""
635668
Create a new branch (server replica) of your Hypernode.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 TestGetActiveBranchers(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_get_active_branchers_endpoint_properly(self):
21+
self.client.get_active_branchers(self.app_name)
22+
23+
self.mock_request.assert_called_once_with(
24+
"GET", f"/v2/app/{self.app_name}/brancher/"
25+
)
26+
27+
def test_returns_active_branchers_data(self):
28+
response = Mock()
29+
response.status_code = 200
30+
self.mock_request.return_value = response
31+
32+
self.assertEqual(
33+
self.client.get_active_branchers(self.app_name),
34+
self.mock_request.return_value,
35+
)

0 commit comments

Comments
 (0)