@@ -51,27 +51,28 @@ def setUpTestData(cls):
5151 device_type = devicetype ,
5252 device_role = devicerole ,
5353 )
54- virtual_chassis = VirtualChassis .objects .create (name = "Virtual Chassis 1" )
55- virtual_chassis_member = Device .objects .create (
56- name = "VC Device" ,
57- site = site ,
58- device_type = devicetype ,
59- device_role = devicerole ,
60- virtual_chassis = virtual_chassis ,
61- vc_position = 1 ,
62- )
63- cluster_member = Device .objects .create (
64- name = "Cluster Device" ,
65- site = site ,
66- device_type = devicetype ,
67- device_role = devicerole ,
68- )
69- clustertype = ClusterType .objects .create (name = "Cluster Type 1" )
70- cluster = Cluster .objects .create (
71- name = "Cluster 1" ,
72- type = clustertype ,
73- )
54+ # virtual_chassis = VirtualChassis.objects.create(name="Virtual Chassis 1")
55+ # virtual_chassis_member = Device.objects.create(
56+ # name="VC Device",
57+ # site=site,
58+ # device_type=devicetype,
59+ # device_role=devicerole,
60+ # virtual_chassis=virtual_chassis,
61+ # vc_position=1,
62+ # )
63+ # cluster_member = Device.objects.create(
64+ # name="Cluster Device",
65+ # site=site,
66+ # device_type=devicetype,
67+ # device_role=devicerole,
68+ # )
69+ # clustertype = ClusterType.objects.create(name="Cluster Type 1")
70+ # cluster = Cluster.objects.create(
71+ # name="Cluster 1",
72+ # type=clustertype,
73+ # )
7474 virtual_machine = VirtualMachine .objects .create (name = "VirtualMachine 1" )
75+ virtual_machine .save ()
7576 prefix = Prefix .objects .create (prefix = "10.0.0.0/8" )
7677
7778
@@ -256,12 +257,12 @@ def setUpTestData(cls):
256257 VMInterface (name = "Interface 2" , virtual_machine = virtual_machine ),
257258 )
258259 )
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- )
260+ # prefixes = Prefix.objects.bulk_create(
261+ # (
262+ # Prefix(prefix=IPNetwork("10.0.0.0/24")),
263+ # Prefix(prefix=IPNetwork("192.168.1.0/24")),
264+ # )
265+ # )
265266
266267 def test_acl_interface_assignment_success (self ):
267268 """
@@ -272,18 +273,36 @@ def test_acl_interface_assignment_success(self):
272273 comments = "STANDARD_ACL" ,
273274 type = "standard" ,
274275 default_action = "permit" ,
275- assigned_object_id = 1 ,
276- assigned_object_type = ContentType .objects .get_for_model (Device ),
276+ assigned_object = Device .objects .first (),
277277 )
278278 device_acl .save ()
279279 acl_device_interface = ACLInterfaceAssignment (
280280 access_list = device_acl ,
281281 direction = "ingress" ,
282- assigned_object_id = 1 ,
283- assigned_object_type = ContentType .objects .get_for_model (Interface ),
282+ assigned_object = Interface .objects .first (),
284283 )
285284 acl_device_interface .full_clean ()
286285
286+ def test_aclinterface_assignment_fail (self ):
287+ """
288+ Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the vminterface and direction.
289+ """
290+ device_acl = AccessList (
291+ name = "STANDARD_ACL" ,
292+ comments = "STANDARD_ACL" ,
293+ type = "standard" ,
294+ default_action = "permit" ,
295+ assigned_object = Device .objects .first (),
296+ )
297+ device_acl .save ()
298+ acl_vm_interface = ACLInterfaceAssignment (
299+ access_list = device_acl ,
300+ direction = "ingress" ,
301+ assigned_object = VMInterface .objects .first (),
302+ )
303+ with self .assertRaises (ValidationError ):
304+ acl_vm_interface .full_clean ()
305+
287306 def test_acl_vminterface_assignment_success (self ):
288307 """
289308 Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the vminterface and direction.
0 commit comments