Skip to content

Commit fa9f369

Browse files
committed
feat(tests): Update ACL rule tests for generic fields
Replaces `source_prefix` and `destination_prefix` with generic `source` and `destination` fields in ACL rule tests. Updates test cases to include `source_type`, `source_id`, `destination_type`, and `destination_id` for better alignment with the updated generic model.
1 parent 037dc0c commit fa9f369

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

netbox_acls/tests/api/test_access_list_rules.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
from utilities.testing import APIViewTestCases
44
from virtualization.models import Cluster, ClusterType, VirtualMachine
55

6-
from netbox_acls.choices import *
7-
from netbox_acls.models import *
6+
from netbox_acls.choices import (
7+
ACLActionChoices,
8+
ACLProtocolChoices,
9+
ACLRuleActionChoices,
10+
ACLTypeChoices,
11+
)
12+
from netbox_acls.models import AccessList, ACLExtendedRule, ACLStandardRule
813

914

1015
class ACLStandardRuleAPIViewTestCase(APIViewTestCases.APIViewTestCase):
@@ -98,7 +103,7 @@ def setUpTestData(cls):
98103
index=10,
99104
description="Rule 10",
100105
action=ACLRuleActionChoices.ACTION_PERMIT,
101-
source_prefix=prefix1,
106+
source=prefix1,
102107
),
103108
ACLStandardRule(
104109
access_list=access_list_device,
@@ -112,7 +117,7 @@ def setUpTestData(cls):
112117
index=10,
113118
description="Rule 10",
114119
action=ACLRuleActionChoices.ACTION_DENY,
115-
source_prefix=prefix2,
120+
source=prefix2,
116121
),
117122
)
118123
ACLStandardRule.objects.bulk_create(acl_standard_rules)
@@ -123,14 +128,16 @@ def setUpTestData(cls):
123128
"index": 30,
124129
"description": "Rule 30",
125130
"action": ACLRuleActionChoices.ACTION_DENY,
126-
"source_prefix": prefix2.id,
131+
"source_type": "ipam.prefix",
132+
"source_id": prefix2.id,
127133
},
128134
{
129135
"access_list": access_list_vm.id,
130136
"index": 20,
131137
"description": "Rule 30",
132138
"action": ACLRuleActionChoices.ACTION_PERMIT,
133-
"source_prefix": prefix1.id,
139+
"source_type": "ipam.prefix",
140+
"source_id": prefix1.id,
134141
},
135142
{
136143
"access_list": access_list_vm.id,
@@ -237,9 +244,9 @@ def setUpTestData(cls):
237244
description="Rule 10",
238245
action=ACLRuleActionChoices.ACTION_PERMIT,
239246
protocol=ACLProtocolChoices.PROTOCOL_TCP,
240-
source_prefix=prefix1,
247+
source=prefix1,
241248
source_ports=[22, 443],
242-
destination_prefix=prefix1,
249+
destination=prefix1,
243250
destination_ports=[22, 443],
244251
),
245252
ACLExtendedRule(
@@ -254,8 +261,8 @@ def setUpTestData(cls):
254261
index=10,
255262
description="Rule 10",
256263
action=ACLRuleActionChoices.ACTION_DENY,
257-
source_prefix=prefix2,
258-
destination_prefix=prefix1,
264+
source=prefix2,
265+
destination=prefix1,
259266
),
260267
)
261268
ACLExtendedRule.objects.bulk_create(acl_extended_rules)
@@ -267,9 +274,11 @@ def setUpTestData(cls):
267274
"description": "Rule 30",
268275
"action": ACLRuleActionChoices.ACTION_DENY,
269276
"protocol": ACLProtocolChoices.PROTOCOL_UDP,
270-
"source_prefix": prefix2.id,
277+
"source_type": "ipam.prefix",
278+
"source_id": prefix2.id,
271279
"source_ports": [53],
272-
"destination_prefix": prefix2.id,
280+
"destination_type": "ipam.prefix",
281+
"destination_id": prefix2.id,
273282
"destination_ports": [53],
274283
},
275284
{
@@ -278,8 +287,10 @@ def setUpTestData(cls):
278287
"description": "Rule 30",
279288
"action": ACLRuleActionChoices.ACTION_PERMIT,
280289
"protocol": ACLProtocolChoices.PROTOCOL_ICMP,
281-
"source_prefix": prefix1.id,
282-
"destination_prefix": prefix2.id,
290+
"source_type": "ipam.prefix",
291+
"source_id": prefix1.id,
292+
"destination_type": "ipam.prefix",
293+
"destination_id": prefix2.id,
283294
},
284295
{
285296
"access_list": access_list_vm.id,

netbox_acls/tests/api/test_access_lists.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
from utilities.testing import APIViewTestCases
55
from virtualization.models import Cluster, ClusterType, VirtualMachine, VMInterface
66

7-
from netbox_acls.choices import *
8-
from netbox_acls.models import *
7+
from netbox_acls.choices import (
8+
ACLActionChoices,
9+
ACLAssignmentDirectionChoices,
10+
ACLTypeChoices,
11+
)
12+
from netbox_acls.models import AccessList, ACLInterfaceAssignment
913

1014

1115
class AccessListAPIViewTestCase(APIViewTestCases.APIViewTestCase):

0 commit comments

Comments
 (0)