Skip to content

Commit 4e05452

Browse files
authored
Replace hardcoded string values with Capability enum class attributes (#747)
1 parent 0a1619f commit 4e05452

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
@@ -33,7 +33,7 @@
3333
)
3434
from linode_api4.errors import ApiError
3535
from linode_api4.linode_client import LinodeClient, MonitorClient
36-
from linode_api4.objects import Region
36+
from linode_api4.objects import Capability, Region
3737

3838
ENV_TOKEN_NAME = "LINODE_TOKEN"
3939
ENV_API_URL_NAME = "LINODE_API_URL"
@@ -43,10 +43,10 @@
4343
SKIP_E2E_FIREWALL = "SKIP_E2E_FIREWALL"
4444

4545
ALL_ACCOUNT_AVAILABILITIES = {
46-
"Linodes",
47-
"NodeBalancers",
48-
"Block Storage",
49-
"Kubernetes",
46+
Capability.linodes,
47+
Capability.nodebalancers,
48+
Capability.block_storage,
49+
Capability.lke,
5050
}
5151

5252
logger = logging.getLogger(__name__)
@@ -62,7 +62,7 @@ def get_api_url():
6262

6363
def get_regions(
6464
client: LinodeClient,
65-
capabilities: Optional[Set[str]] = None,
65+
capabilities: Optional[Set[Capability]] = None,
6666
site_type: Optional[str] = None,
6767
):
6868
region_override = os.environ.get(ENV_REGION_OVERRIDE)
@@ -116,7 +116,9 @@ def get_regions(
116116

117117

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

@@ -224,7 +226,11 @@ def create_inbound_rule(ipv4_address, ipv6_address):
224226
def create_linode(test_linode_client, e2e_test_firewall):
225227
client = test_linode_client
226228

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

230236
linode_instance = client.linode.instance_create(
@@ -245,7 +251,11 @@ def create_linode(test_linode_client, e2e_test_firewall):
245251
def create_linode_for_pass_reset(test_linode_client, e2e_test_firewall):
246252
client = test_linode_client
247253

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

@@ -349,7 +359,11 @@ def get_domain_status():
349359
@pytest.fixture(scope="session")
350360
def test_volume(test_linode_client):
351361
client = test_linode_client
352-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
362+
region = get_region(
363+
client,
364+
{Capability.linodes, Capability.firewall},
365+
site_type="core",
366+
)
353367
label = get_test_label(length=8)
354368

355369
volume = client.volume_create(label=label, region=region)
@@ -368,7 +382,7 @@ def get_volume_status():
368382
@pytest.fixture(scope="session")
369383
def test_volume_with_encryption(test_linode_client):
370384
client = test_linode_client
371-
region = get_region(client, {"Block Storage Encryption"})
385+
region = get_region(client, {Capability.blockstorage_encryption})
372386
label = get_test_label(length=8)
373387

374388
volume = client.volume_create(
@@ -400,7 +414,8 @@ def test_nodebalancer(test_linode_client):
400414
label = get_test_label(length=8)
401415

402416
nodebalancer = client.nodebalancer_create(
403-
region=get_region(client, capabilities={"NodeBalancers"}), label=label
417+
region=get_region(client, capabilities={Capability.nodebalancers}),
418+
label=label,
404419
)
405420

406421
yield nodebalancer
@@ -487,11 +502,11 @@ def create_vpc(test_linode_client):
487502
region=get_region(
488503
test_linode_client,
489504
{
490-
"VPCs",
491-
"VPC IPv6 Stack",
492-
"Linode Interfaces",
493-
"Custom VPC IPv4 Ranges",
494-
"Linodes",
505+
Capability.vpcs,
506+
Capability.vpc_ipv6_stack,
507+
Capability.linode_interfaces,
508+
Capability.vpc_custom_ipv4_ranges,
509+
Capability.linodes,
495510
},
496511
),
497512
description="test description",
@@ -509,7 +524,12 @@ def create_vpc_with_rdma_type(test_linode_client):
509524

510525
# GPUDirect RDMA capability not available for now
511526
region = get_region(
512-
test_linode_client, {"VPCs", "VPC IPv6 Stack", "Linode Interfaces"}
527+
test_linode_client,
528+
{
529+
Capability.vpcs,
530+
Capability.vpc_ipv6_stack,
531+
Capability.linode_interfaces,
532+
},
513533
)
514534

515535
vpc = client.vpcs.create(
@@ -579,7 +599,10 @@ def create_vpc_with_ipv4(test_linode_client):
579599

580600
vpc = client.vpcs.create(
581601
label=get_test_label(length=10),
582-
region=get_region(client, {"VPCs", "Custom VPC IPv4 Ranges"}),
602+
region=get_region(
603+
client,
604+
{Capability.vpcs, Capability.vpc_custom_ipv4_ranges},
605+
),
583606
description="integration test vpc with ipv4",
584607
ipv4=[{"range": "10.0.0.0/8"}],
585608
)
@@ -599,13 +622,13 @@ def create_multiple_vpcs(test_linode_client):
599622

600623
vpc_1 = client.vpcs.create(
601624
label,
602-
get_region(test_linode_client, {"VPCs"}),
625+
get_region(test_linode_client, {Capability.vpcs}),
603626
description="test description",
604627
)
605628

606629
vpc_2 = client.vpcs.create(
607630
label_2,
608-
get_region(test_linode_client, {"VPCs"}),
631+
get_region(test_linode_client, {Capability.vpcs}),
609632
description="test description",
610633
)
611634

@@ -624,7 +647,7 @@ def create_placement_group(test_linode_client):
624647

625648
pg = client.placement.group_create(
626649
label,
627-
get_region(test_linode_client, {"Placement Group"}),
650+
get_region(test_linode_client, {Capability.placement_group}),
628651
PlacementGroupType.anti_affinity_local,
629652
PlacementGroupPolicy.flexible,
630653
)
@@ -664,7 +687,11 @@ def pytest_configure(config):
664687
@pytest.fixture(scope="session")
665688
def linode_for_vlan_tests(test_linode_client, e2e_test_firewall):
666689
client = test_linode_client
667-
region = get_region(client, {"Linodes", "Vlans"}, site_type="core")
690+
region = get_region(
691+
client,
692+
{Capability.linodes, Capability.vlans},
693+
site_type="core",
694+
)
668695
label = get_test_label(length=8)
669696

670697
linode_instance = client.linode.instance_create(
@@ -823,7 +850,11 @@ def test_monitor_client(get_monitor_token_for_db_entities):
823850
@pytest.fixture
824851
def create_reserved_ip(test_linode_client):
825852
client = test_linode_client
826-
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
853+
region = get_region(
854+
client,
855+
{Capability.linodes, Capability.firewall},
856+
site_type="core",
857+
)
827858
reserved_ip = client.networking.reserved_ip_create(
828859
region=region, tags=["test"]
829860
)

‎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)