Skip to content

Commit 24dae23

Browse files
authored
new: Add AccountBetaProgram to support self serve beta (#322)
## 📝 Description `AccountBetaProgram` object returns information about a beta program an account enrolled in, including the enrollment information. Customer can also check the list of all enrolled betas and join an active beta program under the account group. Endpoints implemented: ``` GET /account/betas GET /account/betas/id POST /account/betas ``` ## ✔️ How to Test `tox`
1 parent ddf36d6 commit 24dae23

6 files changed

Lines changed: 136 additions & 0 deletions

File tree

linode_api4/groups/account.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from linode_api4.groups import Group
33
from linode_api4.objects import (
44
Account,
5+
AccountBetaProgram,
56
AccountSettings,
7+
Base,
68
Event,
79
Invoice,
810
Login,
@@ -448,3 +450,34 @@ def user_create(self, email, username, restricted=True):
448450

449451
u = User(self.client, result["username"], result)
450452
return u
453+
454+
def enrolled_betas(self, *filters):
455+
"""
456+
Returns a list of all Beta Programs an account is enrolled in.
457+
458+
API doc: TBD
459+
460+
:returns: a list of Beta Programs.
461+
:rtype: PaginatedList of AccountBetaProgram
462+
"""
463+
return self.client._get_and_filter(AccountBetaProgram, *filters)
464+
465+
def join_beta_program(self, beta):
466+
"""
467+
Enrolls an account into a beta program.
468+
469+
API doc: TBD
470+
471+
:param beta: The object or id of a beta program to join.
472+
:type beta: BetaProgram or str
473+
474+
:returns: A boolean indicating whether the account joined a beta program successfully.
475+
:rtype: bool
476+
"""
477+
478+
self.client.post(
479+
"/account/betas",
480+
data={"id": beta.id if issubclass(type(beta), Base) else beta},
481+
)
482+
483+
return True

linode_api4/objects/account.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,20 @@ def save(self):
637637
self._populate(result)
638638

639639
return True
640+
641+
642+
class AccountBetaProgram(Base):
643+
"""
644+
The details and enrollment information of a Beta program that an account is enrolled in.
645+
"""
646+
647+
api_endpoint = "/account/betas/{id}"
648+
649+
properties = {
650+
"id": Property(identifier=True),
651+
"label": Property(),
652+
"description": Property(),
653+
"started": Property(is_datetime=True),
654+
"ended": Property(is_datetime=True),
655+
"enrolled": Property(is_datetime=True),
656+
}

test/fixtures/account_betas.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"data": [
3+
{
4+
"id": "cool",
5+
"label": "\r\n\r\nRepellat consequatur sunt qui.",
6+
"enrolled": "2018-01-02T03:04:05",
7+
"description": "Repellat consequatur sunt qui. Fugit eligendi ipsa et assumenda ea aspernatur esse. A itaque iste distinctio qui voluptas eum enim ipsa.",
8+
"started": "2018-01-02T03:04:05",
9+
"ended": "2018-01-02T03:04:05"
10+
}
11+
],
12+
"page": 1,
13+
"pages": 1,
14+
"results": 1
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "cool",
3+
"label": "\r\n\r\nRepellat consequatur sunt qui.",
4+
"enrolled": "2018-01-02T03:04:05",
5+
"description": "Repellat consequatur sunt qui. Fugit eligendi ipsa et assumenda ea aspernatur esse. A itaque iste distinctio qui voluptas eum enim ipsa.",
6+
"started": "2018-01-02T03:04:05",
7+
"ended": "2018-01-02T03:04:05"
8+
}

test/unit/linode_client_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from test.unit.base import ClientBaseCase
33

44
from linode_api4 import LongviewSubscription
5+
from linode_api4.objects.beta import BetaProgram
56
from linode_api4.objects.linode import Instance
67
from linode_api4.objects.networking import IPAddress
78
from linode_api4.objects.object_storage import (
@@ -411,6 +412,48 @@ def test_payments(self):
411412
self.assertEqual(payment.date, datetime(2015, 1, 1, 5, 1, 2))
412413
self.assertEqual(payment.usd, 1000)
413414

415+
def test_enrolled_betas(self):
416+
"""
417+
Tests that enrolled beta programs can be retrieved
418+
"""
419+
enrolled_betas = self.client.account.enrolled_betas()
420+
421+
self.assertEqual(len(enrolled_betas), 1)
422+
beta = enrolled_betas[0]
423+
424+
self.assertEqual(beta.id, "cool")
425+
self.assertEqual(beta.enrolled, datetime(2018, 1, 2, 3, 4, 5))
426+
self.assertEqual(beta.started, datetime(2018, 1, 2, 3, 4, 5))
427+
self.assertEqual(beta.ended, datetime(2018, 1, 2, 3, 4, 5))
428+
429+
def test_join_beta_program(self):
430+
"""
431+
Tests that user can join a beta program
432+
"""
433+
join_beta_url = "/account/betas"
434+
with self.mock_post({}) as m:
435+
self.client.account.join_beta_program("cool_beta")
436+
self.assertEqual(
437+
m.call_data,
438+
{
439+
"id": "cool_beta",
440+
},
441+
)
442+
self.assertEqual(m.call_url, join_beta_url)
443+
444+
# Test that user can join a beta program with an BetaProgram object
445+
with self.mock_post({}) as m:
446+
self.client.account.join_beta_program(
447+
BetaProgram(self.client, "cool_beta")
448+
)
449+
self.assertEqual(
450+
m.call_data,
451+
{
452+
"id": "cool_beta",
453+
},
454+
)
455+
self.assertEqual(m.call_url, join_beta_url)
456+
414457

415458
class BetaProgramGroupTest(ClientBaseCase):
416459
"""

test/unit/objects/account_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from linode_api4.objects import (
55
Account,
6+
AccountBetaProgram,
67
AccountSettings,
78
Database,
89
Domain,
@@ -240,3 +241,22 @@ def test_service_transfer_accept(self):
240241
self.assertEqual(
241242
m.call_url, "/account/service-transfers/12345/accept"
242243
)
244+
245+
246+
class AccountBetaProgramTest(ClientBaseCase):
247+
"""
248+
Tests methods of the AccountBetaProgram
249+
"""
250+
251+
def test_account_beta_program_api_get(self):
252+
beta_id = "cool"
253+
account_beta_url = "/account/betas/{}".format(beta_id)
254+
255+
with self.mock_get(account_beta_url) as m:
256+
beta = AccountBetaProgram(self.client, beta_id)
257+
self.assertEqual(beta.id, beta_id)
258+
self.assertEqual(beta.enrolled, datetime(2018, 1, 2, 3, 4, 5))
259+
self.assertEqual(beta.started, datetime(2018, 1, 2, 3, 4, 5))
260+
self.assertEqual(beta.ended, datetime(2018, 1, 2, 3, 4, 5))
261+
262+
self.assertEqual(m.call_url, account_beta_url)

0 commit comments

Comments
 (0)