Skip to content

Commit 2d9a09e

Browse files
authored
test: Add missing integration tests to improve coverage for identified gaps (#429)
* Fill in test gaps in models and improve fixtures * address pr comment and add one more test * make format
1 parent 4bc4a21 commit 2d9a09e

File tree

8 files changed

+218
-30
lines changed

8 files changed

+218
-30
lines changed

test/integration/conftest.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def get_api_url():
2727
return os.environ.get(ENV_API_URL_NAME, "https://api.linode.com/v4beta")
2828

2929

30+
def get_random_label():
31+
timestamp = str(time.time_ns())[:-5]
32+
label = "label_" + timestamp
33+
34+
return label
35+
36+
3037
def get_region(client: LinodeClient, capabilities: Set[str] = None):
3138
region_override = os.environ.get(ENV_REGION_OVERRIDE)
3239

@@ -329,7 +336,7 @@ def test_sshkey(test_linode_client, ssh_key_gen):
329336

330337

331338
@pytest.fixture
332-
def ssh_keys_object_storage(test_linode_client):
339+
def access_keys_object_storage(test_linode_client):
333340
client = test_linode_client
334341
label = "TestSDK-obj-storage-key"
335342
key = client.object_storage.keys_create(label)
@@ -364,8 +371,10 @@ def test_firewall(test_linode_client):
364371
@pytest.fixture
365372
def test_oauth_client(test_linode_client):
366373
client = test_linode_client
374+
label = get_random_label() + "_oauth"
375+
367376
oauth_client = client.account.oauth_client_create(
368-
"test-oauth-client", "https://localhost/oauth/callback"
377+
label, "https://localhost/oauth/callback"
369378
)
370379

371380
yield oauth_client

test/integration/linode_client/test_linode_client.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -353,26 +353,6 @@ def test_fails_to_create_cluster_with_invalid_version(test_linode_client):
353353
assert e.status == 400
354354

355355

356-
# ProfileGroupTest
357-
358-
359-
def test_get_sshkeys(test_linode_client, test_sshkey):
360-
client = test_linode_client
361-
362-
ssh_keys = client.profile.ssh_keys()
363-
364-
ssh_labels = [i.label for i in ssh_keys]
365-
366-
assert test_sshkey.label in ssh_labels
367-
368-
369-
def test_ssh_key_create(test_sshkey, ssh_key_gen):
370-
pub_key = ssh_key_gen[0]
371-
key = test_sshkey
372-
373-
assert pub_key == key._raw_json["ssh_key"]
374-
375-
376356
# ObjectStorageGroupTests
377357

378358

@@ -385,18 +365,18 @@ def test_get_object_storage_clusters(test_linode_client):
385365
assert "us-east" in clusters[0].region.id
386366

387367

388-
def test_get_keys(test_linode_client, ssh_keys_object_storage):
368+
def test_get_keys(test_linode_client, access_keys_object_storage):
389369
client = test_linode_client
390-
key = ssh_keys_object_storage
370+
key = access_keys_object_storage
391371

392372
keys = client.object_storage.keys()
393373
key_labels = [i.label for i in keys]
394374

395375
assert key.label in key_labels
396376

397377

398-
def test_keys_create(test_linode_client, ssh_keys_object_storage):
399-
key = ssh_keys_object_storage
378+
def test_keys_create(test_linode_client, access_keys_object_storage):
379+
key = access_keys_object_storage
400380

401381
assert type(key) == type(
402382
ObjectStorageKeys(client=test_linode_client, id="123")

test/integration/login_client/test_login_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_get_oathclient(test_linode_client, test_oauth_client):
3232

3333
oauth_client = client.load(OAuthClient, test_oauth_client.id)
3434

35-
assert "test-oauth-client" == oauth_client.label
35+
assert "_oauth" in test_oauth_client.label
3636
assert "https://localhost/oauth/callback" == oauth_client.redirect_uri
3737

3838

test/integration/models/account/test_account.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
from datetime import datetime
23
from test.integration.helpers import get_test_label
34

45
import pytest
@@ -91,7 +92,6 @@ def test_get_user(test_linode_client):
9192

9293
assert username == user.username
9394
assert "email" in user._raw_json
94-
assert "email" in user._raw_json
9595

9696

9797
def test_list_child_accounts(test_linode_client):
@@ -102,3 +102,25 @@ def test_list_child_accounts(test_linode_client):
102102
child_account = ChildAccount(client, child_accounts[0].euuid)
103103
child_account._api_get()
104104
child_account.create_token()
105+
106+
107+
def test_get_invoice(test_linode_client):
108+
client = test_linode_client
109+
110+
invoices = client.account.invoices()
111+
112+
if len(invoices) > 0:
113+
assert isinstance(invoices[0].subtotal, float)
114+
assert isinstance(invoices[0].tax, float)
115+
assert isinstance(invoices[0].total, float)
116+
assert r"'billing_source': 'linode'" in str(invoices[0]._raw_json)
117+
118+
119+
def test_get_payments(test_linode_client):
120+
client = test_linode_client
121+
122+
payments = client.account.payments()
123+
124+
if len(payments) > 0:
125+
assert isinstance(payments[0].date, datetime)
126+
assert isinstance(payments[0].usd, float)

test/integration/models/lke/test_lke.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import re
23
from test.integration.helpers import (
34
get_test_label,
@@ -95,9 +96,17 @@ def test_cluster_dashboard_url_view(lke_cluster):
9596
assert re.search("https://+", url)
9697

9798

98-
def test_kubeconfig_delete(lke_cluster):
99+
def test_get_and_delete_kubeconfig(lke_cluster):
99100
cluster = lke_cluster
100101

102+
kubeconfig_encoded = cluster.kubeconfig
103+
104+
kubeconfig_decoded = base64.b64decode(kubeconfig_encoded).decode("utf-8")
105+
106+
assert "kind: Config" in kubeconfig_decoded
107+
108+
assert "apiVersion:" in kubeconfig_decoded
109+
101110
res = send_request_when_resource_available(300, cluster.kubeconfig_delete)
102111

103112
assert res is None

test/integration/models/longview/test_longview.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
import pytest
55

6-
from linode_api4.objects import LongviewClient, LongviewSubscription
6+
from linode_api4.objects import (
7+
ApiError,
8+
LongviewClient,
9+
LongviewPlan,
10+
LongviewSubscription,
11+
)
712

813

914
@pytest.mark.smoke
@@ -46,3 +51,25 @@ def test_get_longview_subscription(test_linode_client, test_longview_client):
4651

4752
assert re.search("[0-9]+", str(sub.price.hourly))
4853
assert re.search("[0-9]+", str(sub.price.monthly))
54+
55+
assert "longview-3" in str(subs.lists)
56+
assert "longview-10" in str(subs.lists)
57+
assert "longview-40" in str(subs.lists)
58+
assert "longview-100" in str(subs.lists)
59+
60+
61+
def test_longview_plan_update_method_not_allowed(test_linode_client):
62+
try:
63+
test_linode_client.longview.longview_plan_update("longview-100")
64+
except ApiError as e:
65+
assert e.status == 405
66+
assert "Method Not Allowed" in str(e)
67+
68+
69+
def test_get_current_longview_plan(test_linode_client):
70+
lv_plan = test_linode_client.load(LongviewPlan, "")
71+
72+
if lv_plan.label is not None:
73+
assert "Longview" in lv_plan.label
74+
assert "hourly" in lv_plan.price.dict
75+
assert "monthly" in lv_plan.price.dict
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import time
2+
from test.integration.conftest import get_region
3+
4+
import pytest
5+
6+
from linode_api4.objects import (
7+
ObjectStorageACL,
8+
ObjectStorageBucket,
9+
ObjectStorageCluster,
10+
ObjectStorageKeys,
11+
)
12+
13+
14+
@pytest.fixture(scope="session")
15+
def test_object_storage_bucket(test_linode_client):
16+
client = test_linode_client
17+
18+
region = get_region(client, {"Object Storage"})
19+
cluster_region_name = region.id + "-1"
20+
label = str(time.time_ns())[:-5] + "-bucket"
21+
22+
bucket = client.object_storage.bucket_create(
23+
cluster=cluster_region_name, label=label
24+
)
25+
26+
yield bucket
27+
28+
bucket.delete()
29+
30+
31+
def test_list_obj_storage_bucket(
32+
test_linode_client, test_object_storage_bucket
33+
):
34+
client = test_linode_client
35+
36+
buckets = client.object_storage.buckets()
37+
target_bucket = test_object_storage_bucket
38+
39+
bucket_ids = [bucket.id for bucket in buckets]
40+
41+
assert target_bucket.id in bucket_ids
42+
assert isinstance(target_bucket, ObjectStorageBucket)
43+
44+
45+
def test_bucket_access_modify(test_object_storage_bucket):
46+
bucket = test_object_storage_bucket
47+
48+
res = bucket.access_modify(ObjectStorageACL.PRIVATE, cors_enabled=True)
49+
50+
assert res
51+
52+
53+
def test_bucket_access_update(test_object_storage_bucket):
54+
bucket = test_object_storage_bucket
55+
res = bucket.access_update(ObjectStorageACL.PRIVATE, cors_enabled=True)
56+
57+
assert res
58+
59+
60+
def test_get_ssl_cert(test_object_storage_bucket):
61+
bucket = test_object_storage_bucket
62+
63+
res = bucket.ssl_cert().ssl
64+
65+
assert res is False
66+
67+
68+
def test_create_key_for_specific_bucket(
69+
test_linode_client, test_object_storage_bucket
70+
):
71+
client = test_linode_client
72+
bucket = test_object_storage_bucket
73+
keys = client.object_storage.keys_create(
74+
"restricted-keys",
75+
bucket_access=client.object_storage.bucket_access(
76+
bucket.cluster, bucket.id, "read_write"
77+
),
78+
)
79+
80+
assert isinstance(keys, ObjectStorageKeys)
81+
assert keys.bucket_access[0].bucket_name == bucket.id
82+
assert keys.bucket_access[0].permissions == "read_write"
83+
assert keys.bucket_access[0].cluster == bucket.cluster
84+
85+
86+
def test_get_cluster(test_linode_client, test_object_storage_bucket):
87+
client = test_linode_client
88+
bucket = test_object_storage_bucket
89+
90+
cluster = client.load(ObjectStorageCluster, bucket.cluster)
91+
92+
assert "linodeobjects.com" in cluster.domain
93+
assert cluster.id == bucket.cluster
94+
assert "available" == cluster.status
95+
96+
97+
def test_get_buckets_in_cluster(test_linode_client, test_object_storage_bucket):
98+
client = test_linode_client
99+
bucket = test_object_storage_bucket
100+
101+
cluster = client.load(ObjectStorageCluster, bucket.cluster)
102+
buckets = cluster.buckets_in_cluster()
103+
bucket_ids = [bucket.id for bucket in buckets]
104+
105+
assert bucket.id in bucket_ids
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from linode_api4.objects import PersonalAccessToken, Profile, SSHKey
2+
3+
4+
def test_user_profile(test_linode_client):
5+
client = test_linode_client
6+
7+
profile = client.profile()
8+
9+
assert isinstance(profile, Profile)
10+
11+
12+
def test_get_personal_access_token_objects(test_linode_client):
13+
client = test_linode_client
14+
15+
personal_access_tokens = client.profile.tokens()
16+
17+
if len(personal_access_tokens) > 0:
18+
assert isinstance(personal_access_tokens[0], PersonalAccessToken)
19+
20+
21+
def test_get_sshkeys(test_linode_client, test_sshkey):
22+
client = test_linode_client
23+
24+
ssh_keys = client.profile.ssh_keys()
25+
26+
ssh_labels = [i.label for i in ssh_keys]
27+
28+
assert isinstance(test_sshkey, SSHKey)
29+
assert test_sshkey.label in ssh_labels
30+
31+
32+
def test_ssh_key_create(test_sshkey, ssh_key_gen):
33+
pub_key = ssh_key_gen[0]
34+
key = test_sshkey
35+
36+
assert pub_key == key._raw_json["ssh_key"]

0 commit comments

Comments
 (0)