Skip to content

Commit 6ec5f6e

Browse files
Merge branch 'dev' into dc_specific_pricing
2 parents 5297b74 + 7415f28 commit 6ec5f6e

6 files changed

Lines changed: 139 additions & 1 deletion

File tree

linode_api4/groups/account.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
from typing import Union
2+
13
from linode_api4.errors import UnexpectedResponseError
24
from linode_api4.groups import Group
35
from linode_api4.objects import (
46
Account,
7+
AccountBetaProgram,
58
AccountSettings,
9+
BetaProgram,
610
Event,
711
Invoice,
812
Login,
@@ -448,3 +452,34 @@ def user_create(self, email, username, restricted=True):
448452

449453
u = User(self.client, result["username"], result)
450454
return u
455+
456+
def enrolled_betas(self, *filters):
457+
"""
458+
Returns a list of all Beta Programs an account is enrolled in.
459+
460+
API doc: TBD
461+
462+
:returns: a list of Beta Programs.
463+
:rtype: PaginatedList of AccountBetaProgram
464+
"""
465+
return self.client._get_and_filter(AccountBetaProgram, *filters)
466+
467+
def join_beta_program(self, beta: Union[str, BetaProgram]):
468+
"""
469+
Enrolls an account into a beta program.
470+
471+
API doc: TBD
472+
473+
:param beta: The object or id of a beta program to join.
474+
:type beta: BetaProgram or str
475+
476+
:returns: A boolean indicating whether the account joined a beta program successfully.
477+
:rtype: bool
478+
"""
479+
480+
self.client.post(
481+
"/account/betas",
482+
data={"id": beta.id if isinstance(beta, BetaProgram) else beta},
483+
)
484+
485+
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: 44 additions & 1 deletion
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
def test_account_transfer(self):
415458
"""
416459
Tests that payments can be retrieved
@@ -427,7 +470,7 @@ def test_account_transfer(self):
427470
self.assertEqual(transfer.region_transfers[0].quota, 5010)
428471
self.assertEqual(transfer.region_transfers[0].billable, 0)
429472

430-
473+
431474
class BetaProgramGroupTest(ClientBaseCase):
432475
"""
433476
Tests methods of the BetaProgramGroup

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)