Skip to content

Commit 0bc4ad2

Browse files
Add POST-time firewall devices integration test
1 parent eada81c commit 0bc4ad2

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

linode_api4/groups/networking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def firewall_create(
4343
self,
4444
label: str,
4545
rules: Dict[str, Any],
46-
devices: Optional[Union[FirewallCreateDevicesOptions, Dict[str, Any]]],
46+
devices: Optional[
47+
Union[FirewallCreateDevicesOptions, Dict[str, Any]]
48+
] = None,
4749
**kwargs,
4850
):
4951
"""

test/integration/groups/__init__.py

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from test.integration.conftest import get_region
2+
from test.integration.helpers import get_test_label
3+
4+
import pytest
5+
6+
from linode_api4 import FirewallCreateDevicesOptions
7+
8+
9+
@pytest.fixture
10+
def create_linode_without_firewall(test_linode_client):
11+
"""
12+
WARNING: This is specifically reserved for Firewall testing.
13+
Don't use this if the Linode will not be assigned to a firewall.
14+
"""
15+
16+
client = test_linode_client
17+
region = get_region(client, {"Cloud Firewall"}, "core").id
18+
19+
label = get_test_label()
20+
21+
instance = client.linode.instance_create(
22+
"g6-nanode-1",
23+
region,
24+
label=label,
25+
)
26+
27+
yield client, instance
28+
29+
instance.delete()
30+
31+
32+
@pytest.fixture
33+
def create_firewall_with_device(create_linode_without_firewall):
34+
client, target_instance = create_linode_without_firewall
35+
36+
firewall = client.networking.firewall_create(
37+
get_test_label(),
38+
rules={
39+
"inbound_policy": "DROP",
40+
"outbound_policy": "DROP",
41+
},
42+
devices=FirewallCreateDevicesOptions(linodes=[target_instance.id]),
43+
)
44+
45+
yield firewall, target_instance
46+
47+
firewall.delete()
48+
49+
50+
def test_create_firewall_with_devices(create_firewall_with_device):
51+
firewall, target_instance = create_firewall_with_device
52+
53+
devices = firewall.devices
54+
55+
assert len(devices) == 1
56+
assert devices[0].entity.id == target_instance.id

test/integration/linode_client/test_linode_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
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+
ConfigInterface,
11+
ObjectStorageKeys,
12+
Region,
13+
)
1014

1115

1216
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)