Skip to content

Commit c38efc7

Browse files
committed
Extract fixtures.py for networking
1 parent 7d87294 commit c38efc7

2 files changed

Lines changed: 75 additions & 63 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
3+
from tests.integration.helpers import (
4+
BASE_CMDS,
5+
delete_target_id,
6+
exec_test_command,
7+
)
8+
from tests.integration.linodes.helpers import (
9+
create_linode,
10+
create_linode_and_wait,
11+
DEFAULT_REGION
12+
)
13+
14+
15+
@pytest.fixture
16+
def create_reserved_ip(request):
17+
tags = getattr(request, "param", None)
18+
command = BASE_CMDS["networking"] + [
19+
"reserved-ip-add",
20+
"--region",
21+
DEFAULT_REGION,
22+
"--text",
23+
"--delimiter",
24+
","
25+
]
26+
27+
if tags:
28+
command += ["--tags", tags]
29+
30+
headers, values = get_command_heads_and_vals(command)
31+
yield headers, values
32+
33+
delete_target_id("networking", values[0], "reserved-ip-delete")
34+
35+
36+
@pytest.fixture(scope="package")
37+
def test_linode_id(linode_cloud_firewall):
38+
linode_id = create_linode_and_wait(firewall_id=linode_cloud_firewall)
39+
40+
yield linode_id
41+
42+
delete_target_id(target="linodes", id=linode_id)
43+
44+
45+
@pytest.fixture(scope="package")
46+
def test_linode_id_shared_ipv4(linode_cloud_firewall):
47+
target_region = "us-mia"
48+
49+
linode_ids = (
50+
create_linode(
51+
test_region=target_region, firewall_id=linode_cloud_firewall
52+
),
53+
create_linode(
54+
test_region=target_region, firewall_id=linode_cloud_firewall
55+
),
56+
)
57+
58+
yield linode_ids
59+
60+
for id_num in linode_ids:
61+
delete_target_id(target="linodes", id=id_num)
62+
63+
64+
def get_command_heads_and_vals(command):
65+
result = exec_test_command(command).splitlines()
66+
headers = [item for item in result[0].split(",")]
67+
values = [item for item in result[1].split(",")]
68+
69+
return headers, values

tests/integration/networking/test_networking.py

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,22 @@
88
from tests.integration.helpers import (
99
BASE_CMDS,
1010
assert_headers_in_lines,
11-
delete_target_id,
1211
exec_test_command,
1312
)
14-
from tests.integration.linodes.helpers import (
15-
create_linode,
16-
create_linode_and_wait,
17-
DEFAULT_REGION
13+
from tests.integration.linodes.helpers import DEFAULT_REGION
14+
from tests.integration.networking.fixtures import (
15+
create_reserved_ip,
16+
get_command_heads_and_vals,
17+
test_linode_id,
18+
test_linode_id_shared_ipv4
1819
)
19-
from tests.integration.sharegroups.fixtures import get_region # noqa: F401
2020

2121

2222
RESERVED_IP_HEADERS = [
2323
"address", "type", "public", "rdns", "linode_id", "reserved", "tags"
2424
]
2525

2626

27-
@pytest.fixture
28-
def create_reserved_ip(request):
29-
tags = getattr(request, "param", None)
30-
command = BASE_CMDS["networking"] + [
31-
"reserved-ip-add",
32-
"--region",
33-
DEFAULT_REGION,
34-
"--text",
35-
"--delimiter",
36-
","
37-
]
38-
39-
if tags:
40-
command += ["--tags", tags]
41-
42-
headers, values = get_command_heads_and_vals(command)
43-
yield headers, values
44-
45-
delete_target_id("networking", values[0], "reserved-ip-delete")
46-
47-
48-
@pytest.fixture(scope="package")
49-
def test_linode_id(linode_cloud_firewall):
50-
linode_id = create_linode_and_wait(firewall_id=linode_cloud_firewall)
51-
52-
yield linode_id
53-
54-
delete_target_id(target="linodes", id=linode_id)
55-
56-
57-
@pytest.fixture(scope="package")
58-
def test_linode_id_shared_ipv4(linode_cloud_firewall):
59-
target_region = "us-mia"
60-
61-
linode_ids = (
62-
create_linode(
63-
test_region=target_region, firewall_id=linode_cloud_firewall
64-
),
65-
create_linode(
66-
test_region=target_region, firewall_id=linode_cloud_firewall
67-
),
68-
)
69-
70-
yield linode_ids
71-
72-
for id in linode_ids:
73-
delete_target_id(target="linodes", id=id)
74-
75-
76-
def get_command_heads_and_vals(command):
77-
result = exec_test_command(command).splitlines()
78-
headers = [item for item in result[0].split(",")]
79-
values = [item for item in result[1].split(",")]
80-
81-
return headers, values
82-
83-
8427
def has_shared_ip(linode_id: int, ip: str) -> bool:
8528
shared_ips = json.loads(
8629
exec_test_command(

0 commit comments

Comments
 (0)