Skip to content

Commit 56e9db4

Browse files
committed
Replace hardcoded string values with Capability enum class attributes
1 parent e35b61d commit 56e9db4

18 files changed

Lines changed: 217 additions & 83 deletions

File tree

‎test/integration/conftest.py‎

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333
from linode_api4.errors import ApiError
3434
from linode_api4.linode_client import LinodeClient, MonitorClient
35-
from linode_api4.objects import Region
35+
from linode_api4.objects import Capability, Region
3636

3737
ENV_TOKEN_NAME = "LINODE_TOKEN"
3838
ENV_API_URL_NAME = "LINODE_API_URL"
@@ -42,10 +42,10 @@
4242
SKIP_E2E_FIREWALL = "SKIP_E2E_FIREWALL"
4343

4444
ALL_ACCOUNT_AVAILABILITIES = {
45-
"Linodes",
46-
"NodeBalancers",
47-
"Block Storage",
48-
"Kubernetes",
45+
Capability.linodes,
46+
Capability.nodebalancers,
47+
Capability.block_storage,
48+
Capability.lke,
4949
}
5050

5151
logger = logging.getLogger(__name__)
@@ -61,7 +61,7 @@ def get_api_url():
6161

6262
def get_regions(
6363
client: LinodeClient,
64-
capabilities: Optional[Set[str]] = None,
64+
capabilities: Optional[Set[Capability]] = None,
6565
site_type: Optional[str] = None,
6666
):
6767
region_override = os.environ.get(ENV_REGION_OVERRIDE)
@@ -115,7 +115,9 @@ def get_regions(
115115

116116

117117
def get_region(
118-
client: LinodeClient, capabilities: Set[str] = None, site_type: str = "core"
118+
client: LinodeClient,
119+
capabilities: Optional[Set[Capability]] = None,
120+
site_type: str = "core",
119121
):
120122
return random.choice(get_regions(client, capabilities, site_type))
121123

@@ -223,7 +225,11 @@ def create_inbound_rule(ipv4_address, ipv6_address):
223225
def create_linode(test_linode_client, e2e_test_firewall):
224226
client = test_linode_client
225227

226-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
228+
region = get_region(
229+
client,
230+
{Capability.linodes, Capability.firewall},
231+
site_type="core",
232+
)
227233
label = get_test_label(length=8)
228234

229235
linode_instance = client.linode.instance_create(
@@ -244,7 +250,11 @@ def create_linode(test_linode_client, e2e_test_firewall):
244250
def create_linode_for_pass_reset(test_linode_client, e2e_test_firewall):
245251
client = test_linode_client
246252

247-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
253+
region = get_region(
254+
client,
255+
{Capability.linodes, Capability.firewall},
256+
site_type="core",
257+
)
248258
label = get_test_label(length=8)
249259
password = "aComplex@Password123"
250260

@@ -337,7 +347,11 @@ def get_domain_status():
337347
@pytest.fixture(scope="session")
338348
def test_volume(test_linode_client):
339349
client = test_linode_client
340-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
350+
region = get_region(
351+
client,
352+
{Capability.linodes, Capability.firewall},
353+
site_type="core",
354+
)
341355
label = get_test_label(length=8)
342356

343357
volume = client.volume_create(label=label, region=region)
@@ -356,7 +370,7 @@ def get_volume_status():
356370
@pytest.fixture(scope="session")
357371
def test_volume_with_encryption(test_linode_client):
358372
client = test_linode_client
359-
region = get_region(client, {"Block Storage Encryption"})
373+
region = get_region(client, {Capability.blockstorage_encryption})
360374
label = get_test_label(length=8)
361375

362376
volume = client.volume_create(
@@ -388,7 +402,8 @@ def test_nodebalancer(test_linode_client):
388402
label = get_test_label(length=8)
389403

390404
nodebalancer = client.nodebalancer_create(
391-
region=get_region(client, capabilities={"NodeBalancers"}), label=label
405+
region=get_region(client, capabilities={Capability.nodebalancers}),
406+
label=label,
392407
)
393408

394409
yield nodebalancer
@@ -475,11 +490,11 @@ def create_vpc(test_linode_client):
475490
region=get_region(
476491
test_linode_client,
477492
{
478-
"VPCs",
479-
"VPC IPv6 Stack",
480-
"Linode Interfaces",
481-
"Custom VPC IPv4 Ranges",
482-
"Linodes",
493+
Capability.vpcs,
494+
Capability.vpc_ipv6_stack,
495+
Capability.linode_interfaces,
496+
Capability.vpc_custom_ipv4_ranges,
497+
Capability.linodes,
483498
},
484499
),
485500
description="test description",
@@ -497,7 +512,12 @@ def create_vpc_with_rdma_type(test_linode_client):
497512

498513
# GPUDirect RDMA capability not available for now
499514
region = get_region(
500-
test_linode_client, {"VPCs", "VPC IPv6 Stack", "Linode Interfaces"}
515+
test_linode_client,
516+
{
517+
Capability.vpcs,
518+
Capability.vpc_ipv6_stack,
519+
Capability.linode_interfaces,
520+
},
501521
)
502522

503523
vpc = client.vpcs.create(
@@ -567,7 +587,10 @@ def create_vpc_with_ipv4(test_linode_client):
567587

568588
vpc = client.vpcs.create(
569589
label=get_test_label(length=10),
570-
region=get_region(client, {"VPCs", "Custom VPC IPv4 Ranges"}),
590+
region=get_region(
591+
client,
592+
{Capability.vpcs, Capability.vpc_custom_ipv4_ranges},
593+
),
571594
description="integration test vpc with ipv4",
572595
ipv4=[{"range": "10.0.0.0/8"}],
573596
)
@@ -587,13 +610,13 @@ def create_multiple_vpcs(test_linode_client):
587610

588611
vpc_1 = client.vpcs.create(
589612
label,
590-
get_region(test_linode_client, {"VPCs"}),
613+
get_region(test_linode_client, {Capability.vpcs}),
591614
description="test description",
592615
)
593616

594617
vpc_2 = client.vpcs.create(
595618
label_2,
596-
get_region(test_linode_client, {"VPCs"}),
619+
get_region(test_linode_client, {Capability.vpcs}),
597620
description="test description",
598621
)
599622

@@ -612,7 +635,7 @@ def create_placement_group(test_linode_client):
612635

613636
pg = client.placement.group_create(
614637
label,
615-
get_region(test_linode_client, {"Placement Group"}),
638+
get_region(test_linode_client, {Capability.placement_group}),
616639
PlacementGroupType.anti_affinity_local,
617640
PlacementGroupPolicy.flexible,
618641
)
@@ -652,7 +675,11 @@ def pytest_configure(config):
652675
@pytest.fixture(scope="session")
653676
def linode_for_vlan_tests(test_linode_client, e2e_test_firewall):
654677
client = test_linode_client
655-
region = get_region(client, {"Linodes", "Vlans"}, site_type="core")
678+
region = get_region(
679+
client,
680+
{Capability.linodes, Capability.vlans},
681+
site_type="core",
682+
)
656683
label = get_test_label(length=8)
657684

658685
linode_instance = client.linode.instance_create(
@@ -811,7 +838,11 @@ def test_monitor_client(get_monitor_token_for_db_entities):
811838
@pytest.fixture
812839
def create_reserved_ip(test_linode_client):
813840
client = test_linode_client
814-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
841+
region = get_region(
842+
client,
843+
{Capability.linodes, Capability.firewall},
844+
site_type="core",
845+
)
815846
reserved_ip = client.networking.reserved_ip_create(
816847
region=region, tags=["test"]
817848
)

‎test/integration/filters/fixtures.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import pytest
55

6+
from linode_api4.objects import Capability
7+
68

79
@pytest.fixture(scope="package")
810
def domain_instance(test_linode_client):
@@ -23,7 +25,10 @@ def lke_cluster_instance(test_linode_client):
2325
node_type = test_linode_client.linode.types()[1] # g6-standard-1
2426
version = test_linode_client.lke.versions()[0]
2527

26-
region = get_region(test_linode_client, {"Kubernetes", "Disk Encryption"})
28+
region = get_region(
29+
test_linode_client,
30+
{Capability.lke, Capability.disk_encryption},
31+
)
2732

2833
node_pool = test_linode_client.lke.node_pool(node_type, 3)
2934
label = get_test_label() + "_cluster"

‎test/integration/linode_client/test_linode_client.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
import pytest
77

88
from linode_api4 import ApiError
9-
from linode_api4.objects import ConfigInterface, ObjectStorageKeys, Region
9+
from linode_api4.objects import (
10+
Capability,
11+
ConfigInterface,
12+
ObjectStorageKeys,
13+
Region,
14+
)
1015

1116

1217
def is_tag_created(client, tag_label):
@@ -19,7 +24,11 @@ def is_tag_created(client, tag_label):
1924
@pytest.fixture(scope="session")
2025
def setup_client_and_linode(test_linode_client, e2e_test_firewall):
2126
client = test_linode_client
22-
region = get_region(client, {"Kubernetes", "NodeBalancers"}, "core").id
27+
region = get_region(
28+
client,
29+
{Capability.lke, Capability.nodebalancers},
30+
"core",
31+
).id
2332

2433
label = get_test_label()
2534

@@ -228,7 +237,7 @@ def test_get_account_settings(test_linode_client):
228237
# LinodeGroupTests
229238
def test_create_linode_instance_without_image(test_linode_client):
230239
client = test_linode_client
231-
region = get_region(client, {"Linodes"}, "core").id
240+
region = get_region(client, {Capability.linodes}, "core").id
232241
label = get_test_label()
233242

234243
linode_instance = client.linode.instance_create(
@@ -252,7 +261,11 @@ def test_create_linode_instance_with_image(setup_client_and_linode):
252261

253262
def test_create_linode_with_interfaces(test_linode_client):
254263
client = test_linode_client
255-
region = get_region(client, {"Vlans", "Linodes"}, site_type="core").id
264+
region = get_region(
265+
client,
266+
{Capability.vlans, Capability.linodes},
267+
site_type="core",
268+
).id
256269
label = get_test_label()
257270

258271
linode_instance = client.linode.instance_create(
@@ -325,7 +338,7 @@ def test_cluster_create_with_api_objects(test_linode_client):
325338
client = test_linode_client
326339
node_type = client.linode.types()[1] # g6-standard-1
327340
version = client.lke.versions()[0]
328-
region = get_region(client, {"Kubernetes"})
341+
region = get_region(client, {Capability.lke})
329342
node_pool = client.lke.node_pool(node_type, 3)
330343
label = get_test_label()
331344

@@ -342,7 +355,7 @@ def test_cluster_create_with_api_objects(test_linode_client):
342355
def test_fails_to_create_cluster_with_invalid_version(test_linode_client):
343356
invalid_version = "a.12"
344357
client = test_linode_client
345-
region = get_region(client, {"Kubernetes"}).id
358+
region = get_region(client, {Capability.lke}).id
346359

347360
with pytest.raises(ApiError, match="not valid") as exc_info:
348361
client.lke.cluster_create(

‎test/integration/models/account/test_account.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from linode_api4.objects import (
1313
Account,
1414
AccountSettings,
15+
Capability,
1516
ChildAccount,
1617
Event,
1718
Login,
@@ -100,7 +101,11 @@ def test_update_maintenance_policy(test_linode_client):
100101
def test_latest_get_event(test_linode_client, e2e_test_firewall):
101102
client = test_linode_client
102103

103-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
104+
region = get_region(
105+
client,
106+
{Capability.linodes, Capability.firewall},
107+
site_type="core",
108+
)
104109
label = get_test_label()
105110

106111
linode = client.linode.instance_create(

‎test/integration/models/firewall/test_firewall.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
import pytest
66

7-
from linode_api4.objects import Firewall, FirewallDevice
7+
from linode_api4.objects import Capability, Firewall, FirewallDevice
88

99

1010
@pytest.fixture(scope="session")
1111
def linode_fw(test_linode_client):
1212
client = test_linode_client
13-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
13+
region = get_region(
14+
client,
15+
{Capability.linodes, Capability.firewall},
16+
site_type="core",
17+
)
1418
label = get_test_label()
1519

1620
linode_instance = client.linode.instance_create(

‎test/integration/models/image/test_image.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from linode_api4 import LinodeClient
9-
from linode_api4.objects import Image
9+
from linode_api4.objects import Capability, Image
1010

1111
DISALLOWED_IMAGE_REGIONS = {
1212
"gb-lon",
@@ -30,7 +30,7 @@ def get_image_upload_regions(client: LinodeClient):
3030
region
3131
for region in get_regions(
3232
client,
33-
capabilities={"Linodes", "Object Storage"},
33+
capabilities={Capability.linodes, Capability.object_storage},
3434
site_type="core",
3535
)
3636
if region.id not in DISALLOWED_IMAGE_REGIONS

0 commit comments

Comments
 (0)