@@ -81,10 +81,10 @@ class TestAccessList(BaseTestCase):
8181 """
8282
8383 common_acl_params = {
84- "assigned_object_id" : 1 ,
8584 "type" : "extended" ,
8685 "default_action" : "permit" ,
8786 }
87+ # device = Device.objects.first()
8888
8989 def test_wrong_assigned_object_type_fail (self ):
9090 """
@@ -93,6 +93,7 @@ def test_wrong_assigned_object_type_fail(self):
9393 acl_bad_gfk = AccessList (
9494 name = "TestACL_Wrong_GFK" ,
9595 assigned_object_type = ContentType .objects .get_for_model (Prefix ),
96+ assigned_object_id = Prefix .objects .first (),
9697 ** self .common_acl_params ,
9798 )
9899 with self .assertRaises (ValidationError ):
@@ -105,6 +106,7 @@ def test_alphanumeric_plus_success(self):
105106 acl_good_name = AccessList (
106107 name = "Testacl-Good_Name-1" ,
107108 assigned_object_type = ContentType .objects .get_for_model (Device ),
109+ assigned_object_id = 1 , # TODO - replace with Device.objects.first()
108110 ** self .common_acl_params ,
109111 )
110112 acl_good_name .full_clean ()
@@ -114,15 +116,16 @@ def test_duplicate_name_success(self):
114116 """
115117 Test that AccessList names can be non-unique if associated to different devices.
116118 """
117-
118119 AccessList .objects .create (
119120 name = "GOOD-DUPLICATE-ACL" ,
120121 assigned_object_type = ContentType .objects .get_for_model (Device ),
122+ assigned_object_id = 1 , # TODO - replace with Device.objects.first()
121123 ** self .common_acl_params ,
122124 )
123125 vm_acl = AccessList (
124126 name = "GOOD-DUPLICATE-ACL" ,
125127 assigned_object_type = ContentType .objects .get_for_model (VirtualMachine ),
128+ assigned_object_id = 1 , # TODO - replace with VirtualMachine.objects.first().id,
126129 ** self .common_acl_params ,
127130 )
128131 vm_acl .full_clean ()
@@ -158,7 +161,7 @@ def test_duplicate_name_fail(self):
158161 "name" : "FAIL-DUPLICATE-ACL" ,
159162 "assigned_object_type" : ContentType .objects .get_for_model (Device ),
160163 ** self .common_acl_params ,
161- "assigned_object_id" : 1 ,
164+ "assigned_object_id" : 1 , # TODO - replace with Device.objects.first()
162165 }
163166 acl_1 = AccessList .objects .create (** params )
164167 acl_1 .save ()
@@ -193,7 +196,7 @@ def test_valid_acl_choices(self):
193196 type = acl_type ,
194197 default_action = default_action ,
195198 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()
197200 )
198201 valid_acl_choice .full_clean ()
199202
@@ -209,7 +212,7 @@ def test_invalid_acl_choices(self):
209212 type = valid_acl_types [0 ],
210213 default_action = invalid_acl_default_action_choice ,
211214 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()
213216 )
214217 with self .assertRaises (ValidationError ):
215218 invalid_acl_default_action .full_clean ()
@@ -222,7 +225,7 @@ def test_invalid_acl_choices(self):
222225 type = invalid_acl_type ,
223226 default_action = valid_acl_default_action_choices [0 ],
224227 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()
226229 )
227230 with self .assertRaises (ValidationError ):
228231 invalid_acl_type .full_clean ()
@@ -239,32 +242,68 @@ def setUpTestData(cls):
239242 Extend BaseTestCase's setUpTestData() to create additional data for testing.
240243 """
241244 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+ )
261265
262266 def test_acl_interface_assignment_success (self ):
263267 """
264268 Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the interface and direction.
265269 """
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 ()
268307
269308 def test_acl_interface_assignment_fail (self ):
270309 """
0 commit comments