@@ -65,8 +65,8 @@ def test_acl_interface_assignment_success(self):
6565
6666 def test_acl_interface_assignment_fail (self ):
6767 """
68- Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host
69- and not already assigned to the vminterface and direction .
68+ Test that ACLInterfaceAssignment fails validation if the ACL is not
69+ assigned to the parent host .
7070 """
7171 device_acl = AccessList (
7272 name = "STANDARD_ACL" ,
@@ -83,6 +83,7 @@ def test_acl_interface_assignment_fail(self):
8383 )
8484 with self .assertRaises (ValidationError ):
8585 acl_vm_interface .full_clean ()
86+ acl_vm_interface .save ()
8687
8788 def test_acl_vminterface_assignment_success (self ):
8889 """
@@ -104,20 +105,33 @@ def test_acl_vminterface_assignment_success(self):
104105 )
105106 acl_vm_interface .full_clean ()
106107
107- def test_acl_host_interface_assignment_fail (self ):
108- """
109- Test that ACLInterfaceAssignment fails validation if the ACL is not assigned to the parent host.
110- """
111- pass
112- # TODO: test_acl_interface_assignment_fail - VM & Device
113-
114108 def test_duplicate_assignment_fail (self ):
115109 """
116110 Test that ACLInterfaceAssignment fails validation
117111 if the ACL already is assigned to the same interface and direction.
118112 """
119- pass
120- # TODO: test_duplicate_assignment_fail - VM & Device
113+ device_acl = AccessList (
114+ name = "STANDARD_ACL" ,
115+ assigned_object = self .device1 ,
116+ type = "standard" ,
117+ default_action = "permit" ,
118+ comments = "STANDARD_ACL" ,
119+ )
120+ device_acl .save ()
121+ acl_device_interface1 = ACLInterfaceAssignment (
122+ access_list = device_acl ,
123+ direction = "ingress" ,
124+ assigned_object = self .device_interface1 ,
125+ )
126+ acl_device_interface1 .full_clean ()
127+ acl_device_interface1 .save ()
128+ acl_device_interface2 = ACLInterfaceAssignment (
129+ access_list = device_acl ,
130+ direction = "ingress" ,
131+ assigned_object = self .device_interface1 ,
132+ )
133+ with self .assertRaises (ValidationError ):
134+ acl_device_interface2 .full_clean ()
121135
122136 def test_acl_already_assigned_fail (self ):
123137 """
@@ -127,4 +141,50 @@ def test_acl_already_assigned_fail(self):
127141 pass
128142 # TODO: test_acl_already_assigned_fail - VM & Device
129143
130- # TODO: Test choices for ACLInterfaceAssignment Model
144+ def test_valid_acl_interface_assignment_choices (self ):
145+ """
146+ Test that ACLInterfaceAssignment action choices using VALID choices.
147+ """
148+ valid_acl_assignment_direction_choices = ["ingress" , "egress" ]
149+
150+ test_acl = AccessList (
151+ name = "STANDARD_ACL" ,
152+ assigned_object = self .device1 ,
153+ type = "standard" ,
154+ default_action = "permit" ,
155+ comments = "STANDARD_ACL" ,
156+ )
157+ test_acl .save ()
158+
159+ for direction_choice in valid_acl_assignment_direction_choices :
160+ valid_acl_assignment = ACLInterfaceAssignment (
161+ access_list = test_acl ,
162+ direction = direction_choice ,
163+ assigned_object = self .device_interface1 ,
164+ comments = f"VALID ACL ASSIGNMENT CHOICES USED: direction={ direction_choice } " ,
165+ )
166+ valid_acl_assignment .full_clean ()
167+
168+ def test_invalid_acl_choices (self ):
169+ """
170+ Test that ACLInterfaceAssignment action choices using INVALID choices.
171+ """
172+ invalid_acl_assignment_direction_choice = "both"
173+
174+ test_acl = AccessList (
175+ name = "STANDARD_ACL" ,
176+ assigned_object = self .device1 ,
177+ type = "standard" ,
178+ default_action = "permit" ,
179+ comments = "STANDARD_ACL" ,
180+ )
181+ test_acl .save ()
182+
183+ invalid_acl_assignment_direction = ACLInterfaceAssignment (
184+ access_list = test_acl ,
185+ direction = invalid_acl_assignment_direction_choice ,
186+ assigned_object = self .device_interface1 ,
187+ comments = f"INVALID ACL DEFAULT CHOICE USED: default_action='{ invalid_acl_assignment_direction_choice } '" ,
188+ )
189+ with self .assertRaises (ValidationError ):
190+ invalid_acl_assignment_direction .full_clean ()
0 commit comments