1
- from dcim .models import Device , DeviceRole , DeviceType , Interface , Manufacturer , Site
1
+ from dcim .models import (
2
+ Device ,
3
+ DeviceRole ,
4
+ DeviceType ,
5
+ Interface ,
6
+ Manufacturer ,
7
+ Site ,
8
+ VirtualChassis ,
9
+ )
2
10
from django .contrib .contenttypes .models import ContentType
3
11
from django .core .exceptions import ValidationError
4
12
from django .test import TestCase
@@ -19,7 +27,7 @@ class BaseTestCase(TestCase):
19
27
def setUpTestData (cls ):
20
28
"""
21
29
Create base data to test using including:
22
- - 1 of each of the following: test site, manufacturer, device type, device role, cluster type, cluster, & virtual machine
30
+ - 1 of each of the following: test site, manufacturer, device type, device role, cluster type, cluster, virtual_chassis, & virtual machine
23
31
- 2 devices, prefixes, 2 interfaces, and 2 vminterfaces
24
32
"""
25
33
@@ -42,6 +50,15 @@ def setUpTestData(cls):
42
50
device_type = devicetype ,
43
51
device_role = devicerole ,
44
52
)
53
+ virtual_chassis = VirtualChassis .objects .create (name = "Virtual Chassis 1" )
54
+ virtual_chassis_member = Device .objects .create (
55
+ name = "VC Device" ,
56
+ site = site ,
57
+ device_type = devicetype ,
58
+ device_role = devicerole ,
59
+ virtual_chassis = virtual_chassis ,
60
+ vc_position = 1 ,
61
+ )
45
62
cluster_member = Device .objects .create (
46
63
name = "Cluster Device" ,
47
64
site = site ,
@@ -55,25 +72,6 @@ def setUpTestData(cls):
55
72
)
56
73
virtual_machine = VirtualMachine .objects .create (name = "VirtualMachine 1" )
57
74
58
- interfaces = Interface .objects .bulk_create (
59
- (
60
- Interface (name = "Interface 1" , device = device , type = "1000baset" ),
61
- Interface (name = "Interface 2" , device = device , type = "1000baset" ),
62
- )
63
- )
64
- vminterfaces = VMInterface .objects .bulk_create (
65
- (
66
- VMInterface (name = "Interface 1" , virtual_machine = virtual_machine ),
67
- VMInterface (name = "Interface 2" , virtual_machine = virtual_machine ),
68
- )
69
- )
70
- prefixes = Prefix .objects .bulk_create (
71
- (
72
- Prefix (prefix = IPNetwork ("10.0.0.0/24" )),
73
- Prefix (prefix = IPNetwork ("192.168.1.0/24" )),
74
- )
75
- )
76
-
77
75
78
76
class TestAccessList (BaseTestCase ):
79
77
"""
@@ -97,6 +95,7 @@ def test_duplicate_name_success(self):
97
95
"""
98
96
Test that AccessList names can be non-unique if associated to different devices.
99
97
"""
98
+
100
99
params = {
101
100
"name" : "GOOD-DUPLICATE-ACL" ,
102
101
"type" : ACLTypeChoices .TYPE_STANDARD ,
@@ -107,13 +106,18 @@ def test_duplicate_name_success(self):
107
106
assigned_object_type = ContentType .objects .get_for_model (Device ),
108
107
assigned_object_id = 1 ,
109
108
)
110
- new_acl = AccessList (
109
+ vm_acl = AccessList (
111
110
** params ,
112
111
assigned_object_type = ContentType .objects .get_for_model (VirtualMachine ),
113
112
assigned_object_id = 1 ,
114
113
)
115
- new_acl .full_clean ()
116
- # TODO: test_duplicate_name_fail - VM & Cluster
114
+ vm_acl .full_clean ()
115
+ vc_acl = AccessList (
116
+ ** params ,
117
+ assigned_object_type = ContentType .objects .get_for_model (VirtualChassis ),
118
+ assigned_object_id = 1 ,
119
+ )
120
+ vc_acl .full_clean ()
117
121
118
122
def test_alphanumeric_plus_fail (self ):
119
123
"""
@@ -144,12 +148,12 @@ def test_duplicate_name_fail(self):
144
148
"type" : ACLTypeChoices .TYPE_STANDARD ,
145
149
"default_action" : ACLActionChoices .ACTION_PERMIT ,
146
150
}
147
- acl_1 = AccessList .objects .create (** params )
151
+ acl_1 = AccessList .objects .create (** params )
148
152
acl_1 .save ()
149
153
acl_2 = AccessList (** params )
150
154
with self .assertRaises (ValidationError ):
151
155
acl_2 .full_clean ()
152
- # TODO: test_duplicate_name_fail - VM & Cluster
156
+ # TODO: test_duplicate_name_fail - VM & VC
153
157
154
158
# TODO: Test choices for AccessList Model
155
159
@@ -159,19 +163,45 @@ class TestACLInterfaceAssignment(BaseTestCase):
159
163
Test ACLInterfaceAssignment model.
160
164
"""
161
165
162
- def test_acl_assignment_success (self ):
166
+ @classmethod
167
+ def setUpTestData (cls ):
168
+ """
169
+ Extend BaseTestCase's setUpTestData() to create additional data for testing.
170
+ """
171
+ super ().setUpTestData ()
172
+
173
+ interfaces = Interface .objects .bulk_create (
174
+ (
175
+ Interface (name = "Interface 1" , device = device , type = "1000baset" ),
176
+ Interface (name = "Interface 2" , device = device , type = "1000baset" ),
177
+ )
178
+ )
179
+ vminterfaces = VMInterface .objects .bulk_create (
180
+ (
181
+ VMInterface (name = "Interface 1" , virtual_machine = virtual_machine ),
182
+ VMInterface (name = "Interface 2" , virtual_machine = virtual_machine ),
183
+ )
184
+ )
185
+ # prefixes = Prefix.objects.bulk_create(
186
+ # (
187
+ # Prefix(prefix=IPNetwork("10.0.0.0/24")),
188
+ # Prefix(prefix=IPNetwork("192.168.1.0/24")),
189
+ # )
190
+ # )
191
+
192
+ def test_acl_interface_assignment_success (self ):
163
193
"""
164
194
Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the interface and direction.
165
195
"""
166
196
pass
167
- # TODO: test_acl_assignment_success - VM & Device
197
+ # TODO: test_acl_interface_assignment_success - VM & Device
168
198
169
- def test_acl_assignment_fail (self ):
199
+ def test_acl_interface_assignment_fail (self ):
170
200
"""
171
201
Test that ACLInterfaceAssignment fails validation if the ACL is not assigned to the parent host.
172
202
"""
173
203
pass
174
- # TODO: test_acl_assignment_fail - VM & Device
204
+ # TODO: test_acl_interface_assignment_fail - VM & Device
175
205
176
206
def test_duplicate_assignment_fail (self ):
177
207
"""
0 commit comments