Skip to content

Commit 8a08c5f

Browse files
Brought longview-related functionality to API parity (#257)
## 📝 Description Brought longview-related functionality to API parity ## ✔️ How to Test `pytest test` Ticket: TPT-1889
1 parent d0f6643 commit 8a08c5f

5 files changed

Lines changed: 105 additions & 2 deletions

File tree

linode_api4/groups/longview.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from linode_api4.errors import UnexpectedResponseError
22
from linode_api4.groups import Group
3-
from linode_api4.objects import LongviewClient, LongviewSubscription
3+
from linode_api4.objects import (
4+
LongviewClient,
5+
LongviewPlan,
6+
LongviewSubscription,
7+
)
48

59

610
class LongviewGroup(Group):
@@ -60,3 +64,40 @@ def subscriptions(self, *filters):
6064
:rtype: PaginatedList of LongviewSubscription
6165
"""
6266
return self.client._get_and_filter(LongviewSubscription, *filters)
67+
68+
def longview_plan_update(self, longview_subscription):
69+
"""
70+
Update your Longview plan to that of the given subcription ID.
71+
72+
:param longview_subscription: The subscription ID for a particular Longview plan.
73+
A value of null corresponds to Longview Free.
74+
:type longview_subscription: str
75+
76+
:returns: The updated Longview Plan
77+
:rtype: LongviewPlan
78+
"""
79+
80+
if longview_subscription not in [
81+
"",
82+
"longview-3",
83+
"longview-10",
84+
"longview-40",
85+
"longview-100",
86+
]:
87+
raise ValueError(
88+
"Invalid longview plan subscription: {}".format(
89+
longview_subscription
90+
)
91+
)
92+
93+
params = {"longview_subscription": longview_subscription}
94+
95+
result = self.client.post(
96+
LongviewPlan.api_endpoint, model=self, data=params
97+
)
98+
99+
plan = LongviewPlan(self.client, result["id"], result)
100+
101+
plan.invalidate()
102+
103+
return plan

linode_api4/objects/longview.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ class LongviewSubscription(Base):
3636
"clients_included": Property(),
3737
"price": Property(),
3838
}
39+
40+
41+
class LongviewPlan(Base):
42+
"""
43+
The current Longview Plan an account is using.
44+
45+
API Documentation: https://www.linode.com/docs/api/longview/#longview-plan-view
46+
"""
47+
48+
api_endpoint = "/longview/plan"
49+
50+
properties = {
51+
"id": Property(identifier=True),
52+
"label": Property(),
53+
"clients_included": Property(),
54+
"price": Property(),
55+
}

test/fixtures/longview_plan.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"clients_included": 10,
3+
"id": "longview-10",
4+
"label": "Longview Pro 10 pack",
5+
"price": {
6+
"hourly": 0.06,
7+
"monthly": 40
8+
}
9+
}

test/linode_client_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,21 @@ def test_client_create_with_label(self):
502502
self.assertEqual(m.call_url, "/longview/clients")
503503
self.assertEqual(m.call_data, {"label": "test_client_1"})
504504

505+
def test_update_plan(self):
506+
"""
507+
Tests that you can submit a correct longview plan update api request
508+
"""
509+
with self.mock_post("/longview/plan") as m:
510+
result = self.client.longview.longview_plan_update("longview-100")
511+
self.assertEqual(m.call_url, "/longview/plan")
512+
self.assertEqual(
513+
m.call_data["longview_subscription"], "longview-100"
514+
)
515+
self.assertEqual(result.id, "longview-10")
516+
self.assertEqual(result.clients_included, 10)
517+
self.assertEqual(result.label, "Longview Pro 10 pack")
518+
self.assertIsNotNone(result.price)
519+
505520
def test_get_subscriptions(self):
506521
"""
507522
Tests that Longview subscriptions can be retrieved

test/objects/longview_test.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
from datetime import datetime
22
from test.base import ClientBaseCase
33

4-
from linode_api4.objects import LongviewClient, LongviewSubscription
4+
from linode_api4.objects import (
5+
LongviewClient,
6+
LongviewPlan,
7+
LongviewSubscription,
8+
)
59
from linode_api4.objects.base import MappedObject
610

711

12+
class LongviewPlanTest(ClientBaseCase):
13+
"""
14+
Tests methods of the LongviewPlan class
15+
"""
16+
17+
def test_get_plan(self):
18+
"""
19+
Tests that a plan is loaded correctly
20+
"""
21+
plan = LongviewPlan(self.client, "longview-10")
22+
23+
self.assertEqual(plan.id, "longview-10")
24+
self.assertEqual(plan.clients_included, 10)
25+
self.assertEqual(plan.label, "Longview Pro 10 pack")
26+
self.assertIsNotNone(plan.price)
27+
28+
829
class LongviewClientTest(ClientBaseCase):
930
"""
1031
Tests methods of the LongviewClient class

0 commit comments

Comments
 (0)