@@ -81,10 +81,10 @@ class TestAccessList(BaseTestCase):
81
81
"""
82
82
83
83
common_acl_params = {
84
- "assigned_object_id" : 1 ,
85
84
"type" : "extended" ,
86
85
"default_action" : "permit" ,
87
86
}
87
+ # device = Device.objects.first()
88
88
89
89
def test_wrong_assigned_object_type_fail (self ):
90
90
"""
@@ -93,6 +93,7 @@ def test_wrong_assigned_object_type_fail(self):
93
93
acl_bad_gfk = AccessList (
94
94
name = "TestACL_Wrong_GFK" ,
95
95
assigned_object_type = ContentType .objects .get_for_model (Prefix ),
96
+ assigned_object_id = Prefix .objects .first (),
96
97
** self .common_acl_params ,
97
98
)
98
99
with self .assertRaises (ValidationError ):
@@ -105,6 +106,7 @@ def test_alphanumeric_plus_success(self):
105
106
acl_good_name = AccessList (
106
107
name = "Testacl-Good_Name-1" ,
107
108
assigned_object_type = ContentType .objects .get_for_model (Device ),
109
+ assigned_object_id = 1 , # TODO - replace with Device.objects.first()
108
110
** self .common_acl_params ,
109
111
)
110
112
acl_good_name .full_clean ()
@@ -114,15 +116,16 @@ def test_duplicate_name_success(self):
114
116
"""
115
117
Test that AccessList names can be non-unique if associated to different devices.
116
118
"""
117
-
118
119
AccessList .objects .create (
119
120
name = "GOOD-DUPLICATE-ACL" ,
120
121
assigned_object_type = ContentType .objects .get_for_model (Device ),
122
+ assigned_object_id = 1 , # TODO - replace with Device.objects.first()
121
123
** self .common_acl_params ,
122
124
)
123
125
vm_acl = AccessList (
124
126
name = "GOOD-DUPLICATE-ACL" ,
125
127
assigned_object_type = ContentType .objects .get_for_model (VirtualMachine ),
128
+ assigned_object_id = 1 , # TODO - replace with VirtualMachine.objects.first().id,
126
129
** self .common_acl_params ,
127
130
)
128
131
vm_acl .full_clean ()
@@ -158,7 +161,7 @@ def test_duplicate_name_fail(self):
158
161
"name" : "FAIL-DUPLICATE-ACL" ,
159
162
"assigned_object_type" : ContentType .objects .get_for_model (Device ),
160
163
** self .common_acl_params ,
161
- "assigned_object_id" : 1 ,
164
+ "assigned_object_id" : 1 , # TODO - replace with Device.objects.first()
162
165
}
163
166
acl_1 = AccessList .objects .create (** params )
164
167
acl_1 .save ()
@@ -193,7 +196,7 @@ def test_valid_acl_choices(self):
193
196
type = acl_type ,
194
197
default_action = default_action ,
195
198
assigned_object_type = ContentType .objects .get_for_model (Device ),
196
- assigned_object_id = 1 ,
199
+ assigned_object_id = 1 , # TODO - replace with Device.objects.first()
197
200
)
198
201
valid_acl_choice .full_clean ()
199
202
@@ -209,7 +212,7 @@ def test_invalid_acl_choices(self):
209
212
type = valid_acl_types [0 ],
210
213
default_action = invalid_acl_default_action_choice ,
211
214
assigned_object_type = ContentType .objects .get_for_model (Device ),
212
- assigned_object_id = 1 ,
215
+ assigned_object_id = 1 , # TODO - replace with Device.objects.first()
213
216
)
214
217
with self .assertRaises (ValidationError ):
215
218
invalid_acl_default_action .full_clean ()
@@ -222,7 +225,7 @@ def test_invalid_acl_choices(self):
222
225
type = invalid_acl_type ,
223
226
default_action = valid_acl_default_action_choices [0 ],
224
227
assigned_object_type = ContentType .objects .get_for_model (Device ),
225
- assigned_object_id = 1 ,
228
+ assigned_object_id = 1 , # TODO - replace with Device.objects.first()
226
229
)
227
230
with self .assertRaises (ValidationError ):
228
231
invalid_acl_type .full_clean ()
@@ -239,32 +242,68 @@ def setUpTestData(cls):
239
242
Extend BaseTestCase's setUpTestData() to create additional data for testing.
240
243
"""
241
244
super ().setUpTestData ()
242
-
243
- # interfaces = Interface.objects.bulk_create(
244
- # (
245
- # Interface(name="Interface 1", device=device, type="1000baset"),
246
- # Interface(name="Interface 2", device=device, type="1000baset"),
247
- # )
248
- # )
249
- # vminterfaces = VMInterface.objects.bulk_create(
250
- # (
251
- # VMInterface(name="Interface 1", virtual_machine=virtual_machine),
252
- # VMInterface(name="Interface 2", virtual_machine=virtual_machine),
253
- # )
254
- # )
255
- # prefixes = Prefix.objects.bulk_create(
256
- # (
257
- # Prefix(prefix=IPNetwork("10.0.0.0/24")),
258
- # Prefix(prefix=IPNetwork("192.168.1.0/24")),
259
- # )
260
- # )
245
+ device = Device .objects .first ()
246
+ interfaces = Interface .objects .bulk_create (
247
+ (
248
+ Interface (name = "Interface 1" , device = device , type = "1000baset" ),
249
+ Interface (name = "Interface 2" , device = device , type = "1000baset" ),
250
+ )
251
+ )
252
+ virtual_machine = VirtualMachine .objects .first ()
253
+ vminterfaces = VMInterface .objects .bulk_create (
254
+ (
255
+ VMInterface (name = "Interface 1" , virtual_machine = virtual_machine ),
256
+ VMInterface (name = "Interface 2" , virtual_machine = virtual_machine ),
257
+ )
258
+ )
259
+ prefixes = Prefix .objects .bulk_create (
260
+ (
261
+ Prefix (prefix = IPNetwork ("10.0.0.0/24" )),
262
+ Prefix (prefix = IPNetwork ("192.168.1.0/24" )),
263
+ )
264
+ )
261
265
262
266
def test_acl_interface_assignment_success (self ):
263
267
"""
264
268
Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the interface and direction.
265
269
"""
266
- pass
267
- # TODO: test_acl_interface_assignment_success - VM & Device
270
+ device_acl = AccessList (
271
+ name = "STANDARD_ACL" ,
272
+ comments = "STANDARD_ACL" ,
273
+ type = "standard" ,
274
+ default_action = "permit" ,
275
+ assigned_object_id = 1 ,
276
+ assigned_object_type = ContentType .objects .get_for_model (Device ),
277
+ )
278
+ device_acl .save ()
279
+ acl_device_interface = ACLInterfaceAssignment (
280
+ access_list_id = device_acl .pk ,
281
+ direction = "ingress" ,
282
+ assigned_object_id = 1 ,
283
+ assigned_object_type = ContentType .objects .get_for_model (Interface ),
284
+ )
285
+ acl_device_interface .full_clean ()
286
+
287
+ def test_acl_vminterface_assignment_success (self ):
288
+ """
289
+ Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the vminterface and direction.
290
+ """
291
+ vm_acl = AccessList (
292
+ name = "STANDARD_ACL" ,
293
+ comments = "STANDARD_ACL" ,
294
+ type = "standard" ,
295
+ default_action = "permit" ,
296
+ assigned_object_id = 1 ,
297
+ assigned_object_type = ContentType .objects .get_for_model (VirtualMachine ),
298
+ )
299
+ vm_acl .save ()
300
+ acl_vm_interface = ACLInterfaceAssignment (
301
+ access_list = vm_acl .pk ,
302
+ direction = "ingress" ,
303
+ assigned_object_id = 1 ,
304
+ assigned_object_type = ContentType .objects .get_for_model (VMInterface ),
305
+ )
306
+ acl_vm_interface .full_clean ()
268
307
269
308
def test_acl_interface_assignment_fail (self ):
270
309
"""
0 commit comments