Skip to content

Commit a94e97b

Browse files
committed
feat(tests): Add generic object tests for ACL rules models
Extend test coverage for ACLStandardRule and ACLExtendedRule to include validation of generic source and destination objects. Add scenarios for aggregates, IP addresses, IP ranges, and validation of invalid objects. Test updates ensure the robustness and accuracy of the new field structure.
1 parent e175528 commit a94e97b

File tree

3 files changed

+426
-86
lines changed

3 files changed

+426
-86
lines changed

netbox_acls/tests/models/base.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
VirtualChassis,
88
)
99
from django.test import TestCase
10-
from ipam.models import Prefix
10+
from ipam.models import RIR, Aggregate, IPAddress, IPRange, Prefix
11+
from netaddr import IPNetwork
1112
from virtualization.models import Cluster, ClusterType, VirtualMachine
1213

1314

@@ -20,12 +21,18 @@ class BaseTestCase(TestCase):
2021
def setUpTestData(cls):
2122
"""
2223
Create base data to test using including
23-
- 1 of each of the following: test site, manufacturer, device type
24+
- 1 of each of the following: rir, site, manufacturer, device type,
2425
device role, cluster type, cluster, virtual chassis, and
2526
virtual machine
26-
- 2 of each Device, prefix
27+
- 2 of each device, aggregate, ip address, ip range, prefix, service
2728
"""
2829

30+
# RIR
31+
rir = RIR.objects.create(
32+
name="RIR 1",
33+
slug="rir-1",
34+
)
35+
2936
# Sites
3037
site = Site.objects.create(
3138
name="Site 1",
@@ -108,10 +115,38 @@ def setUpTestData(cls):
108115
cluster=cluster,
109116
)
110117

118+
# Aggregate
119+
cls.aggregate1 = Aggregate.objects.create(
120+
prefix=IPNetwork("10.0.0.0/8"),
121+
rir=rir,
122+
)
123+
cls.aggregate2 = Aggregate.objects.create(
124+
prefix=IPNetwork("172.16.0.0/12"),
125+
rir=rir,
126+
)
127+
128+
# IP Address
129+
cls.ip_address1 = IPAddress.objects.create(
130+
address=IPNetwork("10.0.0.1/24"),
131+
)
132+
cls.ip_address2 = IPAddress.objects.create(
133+
address=IPNetwork("10.0.0.2/24"),
134+
)
135+
136+
# IP Range
137+
cls.ip_range1 = IPRange.objects.create(
138+
start_address=IPNetwork("10.0.1.1/24"),
139+
end_address=IPNetwork("10.0.1.254/24"),
140+
)
141+
cls.ip_range2 = IPRange.objects.create(
142+
start_address=IPNetwork("10.0.2.1/24"),
143+
end_address=IPNetwork("10.0.2.254/24"),
144+
)
145+
111146
# Prefix
112147
cls.prefix1 = Prefix.objects.create(
113-
prefix="10.1.0.0/16",
148+
prefix=IPNetwork("10.1.0.0/16"),
114149
)
115150
cls.prefix2 = Prefix.objects.create(
116-
prefix="10.2.0.0/16",
151+
prefix=IPNetwork("10.2.0.0/16"),
117152
)

0 commit comments

Comments
 (0)