-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathtest_account.py
More file actions
160 lines (120 loc) · 4.83 KB
/
Copy pathtest_account.py
File metadata and controls
160 lines (120 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import time
from datetime import datetime
from test.integration.conftest import get_region
from test.integration.helpers import get_test_label, retry_sending_request
import pytest
from linode_api4.objects import (
Account,
AccountSettings,
ChildAccount,
Event,
Login,
User,
)
@pytest.mark.smoke
def test_get_account(test_linode_client):
client = test_linode_client
account = client.account()
account_id = account.id
account_get = client.load(Account, account_id)
assert account_get.first_name == account.first_name
assert account_get.last_name == account.last_name
assert account_get.email == account.email
assert account_get.phone == account.phone
assert account_get.address_1 == account.address_1
assert account_get.address_2 == account.address_2
assert account_get.city == account.city
assert account_get.state == account.state
assert account_get.country == account.country
assert account_get.zip == account.zip
assert account_get.tax_id == account.tax_id
def test_get_login(test_linode_client):
client = test_linode_client
login = retry_sending_request(3, client.load, Login(client, "", {}), "")
updated_time = int(time.mktime(getattr(login, "_last_updated").timetuple()))
login_updated = int(time.time()) - updated_time
assert "username" in str(login._raw_json)
assert "ip" in str(login._raw_json)
assert "datetime" in str(login._raw_json)
assert "status" in str(login._raw_json)
assert login_updated < 60
def test_get_account_settings(test_linode_client):
client = test_linode_client
account_settings = client.load(AccountSettings(client, ""), "")
assert "managed" in str(account_settings._raw_json)
assert "network_helper" in str(account_settings._raw_json)
assert "longview_subscription" in str(account_settings._raw_json)
assert "backups_enabled" in str(account_settings._raw_json)
assert "object_storage" in str(account_settings._raw_json)
assert isinstance(account_settings.interfaces_for_new_linodes, str)
assert "maintenance_policy" in str(account_settings._raw_json)
def test_update_maintenance_policy(test_linode_client):
client = test_linode_client
settings = client.load(AccountSettings(client, ""), "")
original_policy = settings.maintenance_policy
new_policy = (
"linode/power_off_on"
if original_policy == "linode/migrate"
else "linode/migrate"
)
settings.maintenance_policy = new_policy
settings.save()
updated = client.load(AccountSettings(client, ""), "")
assert updated.maintenance_policy == new_policy
settings.maintenance_policy = original_policy
settings.save()
updated = client.load(AccountSettings(client, ""), "")
assert updated.maintenance_policy == original_policy
@pytest.mark.smoke
def test_latest_get_event(test_linode_client, e2e_test_firewall):
client = test_linode_client
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
label = get_test_label()
linode, password = client.linode.instance_create(
"g6-nanode-1",
region,
image="linode/debian12",
label=label,
firewall=e2e_test_firewall,
)
try:
for _ in range(5):
events = client.load(Event, "")
latest_events = events._raw_json.get("data", [])[:50]
if any(
event["entity"]["id"] == linode.id for event in latest_events
):
break
time.sleep(1)
else:
assert False, f"Linode '{label}' not found in recent events"
finally:
linode.delete()
def test_get_user(test_linode_client):
client = test_linode_client
profile = client.profile()
user = client.load(User, profile.username)
assert user.username == profile.username
assert "email" in user._raw_json
def test_list_child_accounts(test_linode_client):
pytest.skip("Configure test account settings for Parent child")
client = test_linode_client
child_accounts = client.account.child_accounts()
if len(child_accounts) > 0:
child_account = ChildAccount(client, child_accounts[0].euuid)
child_account._api_get()
child_account.create_token()
def test_get_invoice(test_linode_client):
client = test_linode_client
invoices = client.account.invoices()
if len(invoices) > 0:
assert isinstance(invoices[0].subtotal, float)
assert isinstance(invoices[0].tax, float)
assert isinstance(invoices[0].total, float)
assert r"'billing_source': 'linode'" in str(invoices[0]._raw_json)
def test_get_payments(test_linode_client):
client = test_linode_client
payments = client.account.payments()
if len(payments) > 0:
assert isinstance(payments[0].date, datetime)
assert isinstance(payments[0].usd, float)