Skip to content

Commit 37ca758

Browse files
Clean up test
1 parent 28289e9 commit 37ca758

2 files changed

Lines changed: 28 additions & 37 deletions

File tree

test/integration/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,22 @@ def create_vpc_with_subnet_and_linode(
516516
instance.delete()
517517

518518

519+
@pytest.fixture
520+
def create_vpc_with_ipv4(test_linode_client):
521+
client = test_linode_client
522+
523+
vpc = client.vpcs.create(
524+
label=get_test_label(length=10),
525+
region=get_region(client, {"VPCs", "Custom VPC IPv4 Ranges"}),
526+
description="integration test vpc with ipv4",
527+
ipv4=[{"range": "10.0.0.0/8"}],
528+
)
529+
530+
yield vpc
531+
532+
vpc.delete()
533+
534+
519535
@pytest.fixture(scope="session")
520536
def create_multiple_vpcs(test_linode_client):
521537
client = test_linode_client

test/integration/models/vpc/test_vpc.py

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from test.integration.conftest import get_region
2-
from test.integration.helpers import get_test_label
32

43
import pytest
54

@@ -154,45 +153,21 @@ def test_get_vpc_default_ranges(test_linode_client):
154153
assert len(result.forbidden_ipv4_ranges) > 0
155154

156155

157-
def test_vpc_with_ipv4(test_linode_client):
158-
"""
159-
Tests creating a VPC with ipv4 ranges, getting/listing it,
160-
updating the ipv4, and deleting it.
161-
"""
156+
def test_vpc_with_ipv4(test_linode_client, create_vpc_with_ipv4):
162157
client = test_linode_client
163-
label = get_test_label(length=10)
164-
region = get_region(client, {"VPCs", "Custom VPC IPv4 Ranges"})
165-
166-
# Create
167-
vpc = client.vpcs.create(
168-
label=label,
169-
region=region,
170-
description="integration test vpc with ipv4",
171-
ipv4=[{"range": "10.0.0.0/8"}],
172-
)
158+
vpc = create_vpc_with_ipv4
173159

174-
try:
175-
assert vpc.id is not None
176-
assert vpc.label == label
177-
assert len(vpc.ipv4) > 0
178-
assert vpc.ipv4[0].range == "10.0.0.0/8"
160+
assert vpc.id is not None
161+
assert vpc.ipv4[0].range == "10.0.0.0/8"
179162

180-
# Get by ID
181-
loaded_vpc = client.load(VPC, vpc.id)
182-
assert loaded_vpc.id == vpc.id
183-
assert loaded_vpc.ipv4[0].range == "10.0.0.0/8"
163+
loaded_vpc = client.load(VPC, vpc.id)
164+
assert loaded_vpc.ipv4[0].range == "10.0.0.0/8"
184165

185-
# List and verify present
186-
all_vpcs = client.vpcs()
187-
vpc_ids = [v.id for v in all_vpcs]
188-
assert vpc.id in vpc_ids
166+
all_vpcs = client.vpcs()
167+
assert vpc.id in [v.id for v in all_vpcs]
189168

190-
# Update ipv4
191-
vpc.ipv4 = [{"range": "192.168.0.0/17"}]
192-
vpc.save()
169+
vpc.ipv4 = [{"range": "192.168.0.0/17"}]
170+
vpc.save()
193171

194-
updated_vpc = client.load(VPC, vpc.id)
195-
assert updated_vpc.ipv4[0].range == "192.168.0.0/17"
196-
finally:
197-
# Delete
198-
vpc.delete()
172+
updated_vpc = client.load(VPC, vpc.id)
173+
assert updated_vpc.ipv4[0].range == "192.168.0.0/17"

0 commit comments

Comments
 (0)